在子目录中运行Java程序 [英] Running Java Program in Sub-Directory

查看:109
本文介绍了在子目录中运行Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的格式错误,请提出建议,这是我第一次在此处发布问题.使用UNIX,我无法从顶层目录运行Java程序"Master"(位于子目录中).从顶层进行编译就可以了,但是我实际上不能从顶层运行Java代码.我想我可能会误解classpath/classpath标志.我的目录结构如下:/top-level/src/amsPassageretriever.

Please give suggestions if my formatting is wrong, this is my first time posting a question here. Using UNIX, I'm having trouble running a Java program 'Master' (located in a sub-directory) from the top-level directory. Compiling works just fine from the top-level, but I can't actually run the java code from the top-level. I think I may be misunderstanding classpath / the classpath flag. My directory structure is like so: /top-level/src/amsPassageretriever.

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

When I try to run everything from the top-level directory, I get the following error:

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的参数不是文件,它是类路径(您要执行的主类)内的类的完全限定类名. .

The argument to java is not a file, it is the fully qualified classname of a class inside the classpath (the main class that you want to execute).

这听起来像您想要的类是amsPassageretriever.Master(我假设您在文章末尾打了个错包,叫包amsPassageretrieve).

It sounds like like class you want is amsPassageretriever.Master (I am assuming you made a typo calling the package amsPassageretrieve at the end of your post).

因此,您应该调用:

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中时正常运行,那么您也需要将该目录添加到您的类路径中:

Update: If you want it to run properly when you are not in src then you need to add that directory to your classpath too:

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程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆