我编写了一个程序并将其转换为 jar 文件。 jar 文件在我的电脑上工作得很好。当我尝试在将要运行的服务器上运行该程序时,jar 文件不起作用。我收到这个错误。
Exception in thread "main" java.lang.NoClassDefFoundError: Publish
Caused by: java.lang.ClassNotFoundException: Publish
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Publish. Program will exit.
这个问题我觉得是java版本不同或者环境不同什么的。我认为库不是这里的问题,而是运行该程序的环境。 jar 文件在我自己的电脑上运行完美。
我的java版本 Java 版本“1.6.0_22” Java(TM) SE 运行时环境(build 1.6.0_22-b04) Java HotSpot(TM) 客户端 VM(build 17.1-b03,混合模式,共享)
服务器java版本 Java 版本“1.6.0_24” Java(TM) SE 运行时环境(build 1.6.0_24-b07) Java HotSpot(TM) 64 位服务器 VM(内部版本 19.1-b02,混合模式)
我也收到此错误,这表明我可能有 32 位 java 而服务器有 64 位,这可能会导致问题。
VM初始化时出错 无法为对象堆保留足够的空间
通过分配一些内存来运行这个进程,我很容易地解决了这个错误。
有人知道如何解决这个问题吗?
注意:我也看了manifest文件,好像没问题
最佳答案
您正在使用没有包的Publish
。这意味着 java 需要默认包中的此类。
您需要使用完全限定名称,例如:foo.bar.Publish
来自 documentation :
By default, the first non-option argument is the name of the class to be invoked. A fully-qualified class name should be used. If the -jar option is specified, the first non-option argume nt is the name of a JAR archive containing class and resource f iles for the application, with the startup class indicated by the Main-Class manifest header.
关于java - 程序可以在我的电脑上运行,但不能在服务器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11656363/