问题是,当我通过 Eclipse Juno 通过单击它并“作为 Java 应用程序运行”运行它时,它可以工作,但它需要在 Linux shell 脚本中运行,或者至少从 Linux shell 运行。
我需要它将 $CATALINA_HOME/webapps/myapp/WEB-INF/lib 中的所有 jar 文件附加到我的类路径中。
这是我的代码:
package com.myapp.client;
public class ClientApp {
public static void main(String args[]) {
System.out.println("Hi Client");
}
}
当我 cd 进入 $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com/myapp/client 发出以下命令:
java -classpath "/home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/lib/*:." ClientApp
我收到此异常:
Exception in thread "main" java.lang.NoClassDefFoundError: ClientApp (wrong name: com/myapp/client/ClientApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
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 java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: ClientApp. Program will exit
当我去我的主目录(/home/devuser)并输入这个时,它仍然不起作用:
java -classpath "/home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/lib/*:." $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com.myapp.ClientApp
Exception in thread "main" java.lang.NoClassDefFoundError: /home/devuser/DevTools/apache-tomcat-7/0/32/webapps/myapp/WEB-INF/classes/com/myapp/ClientApp
Caused by: java.lang.ClassNotFoundException: .home.devuser.DevTools.apache-tomcat-7.0.32.webapps.myapp.WEB-INF.classes.com.myapp.ClientApp
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 java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: /home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/classes/com.myapp.ClientApp. Program will exit.
感谢您花时间阅读本文...如果有人可以帮助我,将不胜感激。