gpt4 book ai didi

java - 运行子目录中的Java程序

转载 作者:太空宇宙 更新时间:2023-11-04 08:37:59 24 4
gpt4 key购买 nike

如果我的格式错误,请提出建议,这是我第一次在这里发帖。使用 UNIX,我在从顶级目录运行 Java 程序“Master”(位于子目录中)时遇到问题。从顶层编译工作得很好,但我实际上无法从顶层运行java代码。我想我可能误解了类路径/类路径标志。我的目录结构如下:/top-level/src/amsPassageretriever。

当我尝试从顶级目录运行所有内容时,出现以下错误:

user:~/top-level$ javac -classpath :/NLP_TOOLS/info_retrieval/lucene/latest/lucene-core-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/demo/lucene-demo-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/wordnet/lucene-wordnet-3.1.0.jar:/NLP_TOOLS/info_retrieval/lemur/latest/share/indri/indri.jar src/amsPassageretriever/*.java
user:~/top-level$ java -classpath :/NLP_TOOLS/info_retrieval/lucene/latest/lucene-core-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/demo/lucene-demo-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/wordnet/lucene-wordnet-3.1.0.jar:/NLP_TOOLS/info_retrieval/lemur/latest/share/indri/indri.jar src/amsPassageretriever/Master
Exception in thread "main" java.lang.NoClassDefFoundError: src/amsPassageretriever/Master (wrong name: amsPassageretriever/Master)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: src/amsPassageretriever/Master. Program will exit.

最佳答案

java 的参数不是文件,它是类路径中的类的完全限定类名(您要执行的主类)。

听起来您想要的类是 amsPassageretriever.Master (我假设您在帖子末尾调用了包 amsPassageretrieve )。

因此你应该调用:

java -classpath :/NLP_TOOLS/info_retrieval/lucene/latest/lucene-core-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/demo/lucene-demo-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/wordnet/lucene-wordnet-3.1.0.jar:/NLP_TOOLS/info_retrieval/lemur/latest/share/indri/indri.jar amsPassageretriever.Master

更新:如果您希望它在不在 src 中时也能正常运行,那么您也需要将该目录添加到您的类路径中:

java -classpath /home/user/top-level/src:/NLP_TOOLS/info_retrieval/lucene/latest/lucene-core-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/demo/lucene-demo-3.1.0.jar:/NLP_TOOLS/info_retrieval/lucene/latest/contrib/wordnet/lucene-wordnet-3.1.0.jar:/NLP_TOOLS/info_retrieval/lemur/latest/share/indri/indri.jar amsPassageretriever.Master

关于java - 运行子目录中的Java程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5943879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com