且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jar 找不到主方法 - 连接到主类,但无法访问方法

更新时间:2023-11-16 18:41:34

-cp(和 -classpath)参数在以下情况下被忽略使用 -jar 参数.您需要在 JAR 的 MANIFEST.MF 文件的 Class-Path 属性中指定它.

The -cp (and -classpath) arguments are ignored when using -jar argument. You need to specify it in the Class-Path attribute of JAR's MANIFEST.MF file.

我的蚂蚁有点生锈,但它就像那些线:

My ant is a bit rusty, but it's something like those lines:

<attribute name="Class-Path" value="${dist.classpath}"/>

更新 根据您的评论,您想知道如何直接使用 Eclipse 而不是使用 Ant 来执行此操作.首先,您需要使用 Ctrl+F11 运行建议的 main() 方法,然后右键单击该项目,选择 Export > RunnableJAR 文件(注意Runnable"部分,这很重要!).然后,在向导中,您必须从列表中选择相同的启动配置(如有必要,选择库处理),然后单击完成.这样,Eclipse 会在生成 MANIFEST 文件时自动考虑构建路径详细信息.


Update as per your comments you'd like to know how to do this directly with Eclipse instead of hassling with Ant. First, you need to run the proposed main() method using Ctrl+F11 and then rightclick the project, choose Export > Runnable JAR file (note "Runnable" part, this is important!). Then, in the Wizard you have to choose the same Launch configuration from the list (and if necessary choose library handling) and then click Finish. This way Eclipse will take the buildpath details automagically into account when generating the MANIFEST file.