我在 CompanyUS.ear 中有一个类 DealerProfile.class ,它部署在服务器中。我编写了一个简单的 shell 脚本来调用类“dealerProfile.class” 'com.download.DealerProfile' 是该类所在的包
代码dealerProfile.sh:java com.download.DealerProfile.testShellDealer
我收到此错误
Exception in thread "main" java.lang.NoClassDefFoundError: com.download.DealerProfile.testShellDealer
Caused by: java.lang.ClassNotFoundException: com.download.DealerProfile.testShellDealer
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClass(ClassLoader.java:677)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
Could not find the main class: com.download.DealerProfile.testShellDealer. Program will exit.
我知道我需要将类路径设置为 .ear 中的类文件位置
但我不知道该怎么做。
我第一次发布问题,如果看起来比较业余,请原谅。 非常感谢任何建议。
感谢您花时间阅读该帖子
最佳答案
EAR 文件旨在部署在 JBoss 或类似服务器上。它通常包含 jar 文件和/或 Web 文件(WAR 文件)。 Java 运行时不会像处理 Jar 文件那样执行 EAR 文件(使用 java -jar),因此您无法使用命令行来运行 java 可执行文件。您应该将其放入应用程序服务器中,或者将您的类打包到 Jar 文件中,甚至允许您将 jar 文件嵌套在一起。
在 jar 中运行类的命令如下所示:
java -jar CompanyUS.jar com.download.DealerProfile.testShellDealer
关于java - 从 shell 脚本调用耳朵中存在的 Java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28837506/