使用 Eclipse 创建 jar 文件

发布于 2024-10-06 21:52:39 字数 417 浏览 0 评论 0原文

我需要使用 eclipse IDE 创建一个 jar 文件。但是我面临着将引用 jar 添加到我正在创建的 jar 中的问题...为我的项目创建 jar 后,当我使用命令提示符运行它时(我使用命令提示符,因为我需要输入一个文件作为命令行参数)它给出了一个异常,说“找不到类”,并且该特定类位于引用的 jar 文件中...

我尝试使用以下链接中指示的方式克服我的问题,但问题仍然存在...

http://www.wikihow.com/Add- JARs-to-Project-Build-Paths-in-Eclipse-(Java)

任何人都可以帮我解决这个问题吗?

I need to create a jar file using eclipse IDE. But I am facing with a problem of adding referencing jars to the jar I am creating... after creating a jar for my project, when I run it using command prompt (I use command prompt because I need to input a file as a command line argument) it gives an exception saying "class not found" and that particular class is in that referencing jar file...

I tried to overcome my problem using the way instructed in the following link but still the problem exists...

http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

Can anyone please help me with this? Thanx in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆沫 2024-10-13 21:52:39

您可以使用导出向导创建一个包含所有依赖项的可运行 jar。

转到“导出 > 可运行的 JAR 文件”,然后选择“将所需的库打包到生成的 JAR 中”。

You can create a runnable jar that includes all dependencies using the Export wizard.

Go to "Export > Runnable JAR File", and select "Package required libraries into generated JAR".

指尖微凉心微凉 2024-10-13 21:52:39

您正在创建可执行 jar 吗?使用 eclipse 创建可执行 jar(即:它有一个主类和一个清单)时,有一个包含引用的选项。

Are you creating an executable jar? When creating an executable jar (ie: it has a main class, and a manifest) using eclipse, there is an option to include references.

酷遇一生 2024-10-13 21:52:39

您可以使用 ant 脚本来为您执行此操作:

<target name="dist" description="dist" depends="compile">
    <jar destfile="executable.jar">
            <manifest>
                    <attribute name="Main-Class" value="com.foo.MainClass"/>
            </manifest>     
        <fileset dir="build" />
        <zipfileset src="lib/commons-beanutils.jar"/>           
        <zipfileset src="lib/commons-logging-1.1.jar"/>
            <!-- Replace with your libraries -->
    </jar>  
</target>

http://www.coderslog.com/ANT_SCRIPTS_Executable_Jar_With_Dependencies

You can use an ant script to do that for you:

<target name="dist" description="dist" depends="compile">
    <jar destfile="executable.jar">
            <manifest>
                    <attribute name="Main-Class" value="com.foo.MainClass"/>
            </manifest>     
        <fileset dir="build" />
        <zipfileset src="lib/commons-beanutils.jar"/>           
        <zipfileset src="lib/commons-logging-1.1.jar"/>
            <!-- Replace with your libraries -->
    </jar>  
</target>

http://www.coderslog.com/ANT_SCRIPTS_Executable_Jar_With_Dependencies

零崎曲识 2024-10-13 21:52:39

请注意,您所引用的文章仅告诉您如何将其他 jar 添加到构建路径,以便 Eclipse 可以构建您的项目。运行应用程序时,您的类路径中仍然需要其中一些(或全部)。已经提供的答案提供了有关如何实际将它们添加到应用程序 jar 的更多信息,但您也可以简单地引用使用 -classpath 参数放置所有 jar 的 (lib) 映射。请参阅 http://download.oracle.com/javase/ 1.5.0/docs/tooldocs/windows/classpath.html
因此,基本上,您必须确保在运行时(使用类路径参数或使用其他答案之一)以及构建时(使用您引用的链接中提到的解决方案)引用您需要的 jar。

Note that the article you are referring to only tells you how to add the additional jars to your buildpath, so Eclipse can build your project. You still need some (or all) of them also on your classpath when running your application. The already provided answers give more information on how to actually add them to your application jar, but you can also simply reference to the (lib) map you've placed all the jars in with the -classpath argument. See http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html
So basically you have to make sure that the jars you need are referenced both at runtime (using the classpath argument or using one of the other answers) as well as at build time (using the solution mentioned in the by you referred link).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文