次の起動が Eclipse で機能する理由:
private static MaxentTagger maxentTagger = new MaxentTagger("c:\\DP\\lemma\\models\\english-left3words-distsim.tagger");
しかし、コマンドラインでは次のようにスローされます:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.ExceptionInInitializerError
at dp.beans.MySearch.<init>(MySearch.java:122)
at dp.runable.Main.main(Main.java:25)
... 5 more
Caused by: java.lang.IllegalArgumentException: name
at sun.misc.URLClassPath$Loader.findResource(Unknown Source)
at sun.misc.URLClassPath.findResource(Unknown Source)
at java.net.URLClassLoader$2.run(Unknown Source)
at java.net.URLClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(Unknown Source)
at java.lang.ClassLoader.getResource(Unknown Source)
at java.net.URLClassLoader.getResourceAsStream(Unknown Source)
at edu.stanford.nlp.io.IOUtils.findStreamInClasspathOrFileSystem(IOUtils.java:370)
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:399)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:646)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:284)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:248)
at dp.data.Settings.<clinit>(Settings.java:80)
... 7 more
Settings.java:80
開始に対応MaxentTagger
..
Eclipse と cmd の両方で機能する Windows パスを宣言する別の方法はありますか?
更新(findStreamInClasspathOrFileSystem
メソッド):
private static InputStream [More ...] findStreamInClasspathOrFileSystem(String name) throws FileNotFoundException
{
String path = null;
if (name.startsWith("/")) {
path = name.substring(1);
}
// - even though this may look like a regular file, it may be a path inside a jar in the CLASSPATH
// - check for this first. This takes precedence over the file system.
InputStream is = null;
if (path != null) {
is = IOUtils.class.getClassLoader().getResourceAsStream(path);
// windows File.separator is \, but getting resources only works with /
if (is == null) {
is = IOUtils.class.getClassLoader().getResourceAsStream(path.replaceAll("\\\\", "/"));
}
}
// if not found in the CLASSPATH, load from the file system
if (is == null) is = new FileInputStream(name);
return is;
}
更新:パスを次のように変更しても:
"c:/DP/lemma/models/english-left3words-distsim.tagger");
"c:\\\\DP\\\\lemma\\\\models\\\\english-left3words-distsim.tagger");
その動作は同じです (cmd ではなく、Eclipse で動作します)