这个问题真的让我抓狂
回答大多数人的想法:是的,我将 snowball.jar 添加到 CLASSPATH
我有一个简单的主类,应该将“going”这个词改为“go”:
import weka.core.stemmers.SnowballStemmer;
public class StemmerTest {
public static void main(String[] args) {
SnowballStemmer stemmer = new SnowballStemmer();
stemmer.setStemmer("english");
System.out.println(stemmer.stem("going"));
}
}
首先,当我在 Eclipse 中运行它时,它可以工作,我得到以下输出:
Refreshing GOE props...
---Registering Weka Editors---
Trying to add database driver (JDBC): RmiJdbc.RJDriver - Warning, not in CLASSPATH?
Trying to add database driver (JDBC): jdbc.idbDriver - Warning, not in CLASSPATH?
Trying to add database driver (JDBC): org.gjt.mm.mysql.Driver - Warning, not in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Warning, not in CLASSPATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Warning, not in CLASSPATH?
[KnowledgeFlow] Loading properties and plugins...
[KnowledgeFlow] Initializing KF...
go
但是,当我从 eclipse“stem.jar”将它导出为可运行 jar 并在终端“java -jar stem.jar”中执行它时,它不起作用,我得到以下输出:
Refreshing GOE props...
[KnowledgeFlow] Loading properties and plugins...
[KnowledgeFlow] Initializing KF...
Stemmer 'porter' unknown!
Stemmer 'english' unknown!
going
我不知道为什么在导出的 jar 中无法识别 snowball.jar ...虽然 weka.jar 和 snowball.jar 都包含在导出的 jar 中。这是 stem.jar 文件结构:
stem.jar
|
|---META-INF
|---org
|---StemmerTest.class
|---snowball.jar
|---weka.jar
我将不胜感激任何有关问题的帮助
编辑 1: 生成的 ANT 脚本:
<project default="create_run_jar" name="Create Runnable Jar for Project StemmerTest with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="stem.jar">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="StemmerTest"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./ snowball-2012.jar weka.jar snowball.jar"/>
</manifest>
<zipfileset src="jar-in-jar-loader.zip"/>
<zipfileset dir="resources/lib" includes="snowball-2012.jar"/>
<fileset dir="bin"/>
<zipfileset dir="." includes="weka.jar"/>
<zipfileset dir="." includes="snowball.jar"/>
</jar>
</target>
编辑2:
这是所要求的 MANIFEST.MF 的内容。
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 23.25-b01 (Oracle Corporation)
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Main-Class: StemmerTest
Rsrc-Class-Path: ./ weka.jar snowball.jar
Class-Path: .
提前致谢, TeFa