设置系统属性


70

我正在尝试按照此说明运行嵌入式门

它说:“系统属性gate.home应该设置为gate安装目录。” (http://gate.ac.uk/wiki/code-repository/)

我该怎么做呢?

另外,当我尝试运行EmbeddedAnnie的示例代码时,也会收到以下错误:(我不知道它是否相关)。

Initialising GATE...
GATE home system property ("gate.home") not set.
Attempting to guess...
Using "C:\Program Files (x86)\GATE-6.0" as GATE Home.
If this is not correct please set it manually using the -Dgate.home option in yo
ur start-up script
Using C:\Program Files (x86)\GATE-6.0 as GATE home
Using C:\Program Files (x86)\GATE-6.0\plugins as installed plug-ins directory.
Using C:\Program Files (x86)\GATE-6.0\gate.xml as site configuration file.
Using C:\Users\UNST\gate.xml as user configuration file
Using C:\Users\UNST\gate.session as user session file
Exception in thread "main" java.lang.NoClassDefFoundError: gate/creole/gazetteer
/AbstractGazetteer
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:296)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:296)
        at gate.util.GateClassLoader.loadClass(GateClassLoader.java:63)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at gate.creole.CreoleAnnotationHandler.processAnnotationsForResource(Cre
oleAnnotationHandler.java:193)
        at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati
onHandler.java:169)
        at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati
onHandler.java:173)
        at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati
onHandler.java:173)
        at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati
onHandler.java:157)
        at gate.creole.CreoleRegisterImpl.processFullCreoleXmlTree(CreoleRegiste
rImpl.java:358)
        at gate.creole.CreoleRegisterImpl.parseDirectory(CreoleRegisterImpl.java
:341)
        at gate.creole.CreoleRegisterImpl.registerDirectories(CreoleRegisterImpl
.java:306)
        at gate.Gate.initCreoleRepositories(Gate.java:449)
        at gate.Gate.init(Gate.java:230)
        at StandAloneAnnie.main(StandAloneAnnie.java:69)
Caused by: java.lang.ClassNotFoundException: gate.creole.gazetteer.AbstractGazet
teer
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 27 more

特德

Answers:


136

您可以通过几种方式来实现。

一种是在运行应用程序时,可以向其传递一个标志。

java -Dgate.home="http://gate.ac.uk/wiki/code-repository" your_application

或在需要此属性的代码段之前以编程方式在代码中进行设置。Java保留Properties用于System广泛配置的对象。

Properties props = System.getProperties();
props.setProperty("gate.home", "http://gate.ac.uk/wiki/code-repository");

14
+1-但是,以编程方式设置系统属性的陷阱是您需要足够早地进行设置;即在“门”代码使用属性值之前。
Stephen C

1
@StephenC,是啊,比如设置java.system.class.loader
Pacerier

@Pacerier-这是一个在命令行设置时有效的属性示例。
Stephen C

@StephenC,这是因为使用属性值的“门”代码在用户代码的第一行之前。
Pacerier,2014年

1
@Sayantan除了我7年前写的这个答案外,我的Java经验远没有现在丰富。
wkl


6
System.setProperty("gate.home", "/some/directory"); 

之后,您可以稍后通过调用来获取其值

String value =  System.getProperty("gate.home");

1
请也解释一下。
Lakshmi 2014年


3

您需要本地GATE安装的plugins目录的路径。因此,如果Gate安装在“ /home/user/GATE_Developer_8.1”中,则代码如下所示:

System.setProperty("gate.home", "/home/user/GATE_Developer_8.1/plugins");

您不必从命令行设置gate.home。您可以在应用程序中进行设置,只要在调用Gate.init()之前进行设置即可。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.