Getting在Java中找不到主类:错误,即使Manifest指定了该类
这是一个非常常见的错误,由于我是Java新手,我可能会误解其他人的答案: 在带有JRE 1.6的Windows 7上 我从Restlet复制了First Steps软件包,作为一个独立的应用程序在我自己身上进行了尝试。我有一个名为FirstStepsMain的类(请参见下面的class),并在我的清单(请参见下面的Manifest)中将其定义为“主类:firstSteps.FirstStepsMain”。我在Windows中将类路径变量设置为\firstSteps.jar。考虑到可能没有看到外部jar,我将它们移到了同一个文件夹中,并为它们设置了Windows类路径 我甚至在第一个Jar和所有三个Jar中使用了-classpath命令:Getting在Java中找不到主类:错误,即使Manifest指定了该类,java,windows-7,restlet,Java,Windows 7,Restlet,这是一个非常常见的错误,由于我是Java新手,我可能会误解其他人的答案: 在带有JRE 1.6的Windows 7上 我从Restlet复制了First Steps软件包,作为一个独立的应用程序在我自己身上进行了尝试。我有一个名为FirstStepsMain的类(请参见下面的class),并在我的清单(请参见下面的Manifest)中将其定义为“主类:firstSteps.FirstStepsMain”。我在Windows中将类路径变量设置为\firstSteps.jar。考虑到可能没有看到外部
E:\ResultsDashboard>java -verbose -classpath e:\ResultsDashboard\firstSteps.jar;e:\resultsdashboard\org.restlet.jar;E:\ResultsDashboardorg.restlet.ext.servlet.jar -jar firstSteps.jar
但我仍然得到了错误。任何帮助都将不胜感激
类:
package firstSteps;
import org.restlet.Component;
import org.restlet.data.Protocol;
public class FirstStepsMain {
public static void main(String[] args) throws Exception {
// Create a new Component.
Component component = new Component();
// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);
// Attach the sample application.
component.getDefaultHost().attach("/firstSteps",
new FirstStepsApplication());
// Start the component.
component.start();
}
}
Manifest-Version: 1.0
Main-Class: firstSteps.FirstStepsMain
Class-Path: firstSteps.jar [note: I added this as a desperate attempt]
清单:
package firstSteps;
import org.restlet.Component;
import org.restlet.data.Protocol;
public class FirstStepsMain {
public static void main(String[] args) throws Exception {
// Create a new Component.
Component component = new Component();
// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);
// Attach the sample application.
component.getDefaultHost().attach("/firstSteps",
new FirstStepsApplication());
// Start the component.
component.start();
}
}
Manifest-Version: 1.0
Main-Class: firstSteps.FirstStepsMain
Class-Path: firstSteps.jar [note: I added this as a desperate attempt]
您需要将
Main类:firstSteps.FirstStepsMain
放入清单文件的第二行。请参见当您使用
-jar
选项启动Java程序时,命令行上的-classpath
选项将被忽略。因此,你在这里指定什么并不重要
相反,您必须在清单文件中指定类路径。将程序所需的所有jar添加到清单文件中的类路径
属性中,而不是firstSteps.jar
本身。例如,它应该如下所示:
Class-Path: org.restlet.jar org.restlet.ext.servlet.jar
请参见教程中的
然后,您应该能够使用以下工具运行它:
java -jar firstSteps.jar
就在那里。。。在我原来的帖子上,剪贴的内容不正确。清单内容为:清单版本:1.0主类:firstSteps.FirstStepsMainThank。看到jarsI的例子有助于我把它具体化。