我最近完成了大学 Java 作业。该作业使用了各种其他 jar 文件,例如 mysql 连接器。当我从项目中的 Java 程序创建 jar 文件时,与这些其他 jar 文件的连接丢失了。
我在创建 jar 文件时尝试了各种不同的组合,并一度包含了 mysql 连接器,但无济于事。我没想到这会起作用,因为我的研究表明通常只有声音效果和图像被归类为可接受的附加文件。
所有内容都在同一目录中,并且各个 jar 文件的所有类路径都是相对的。我的 IDE 是 jGrasp。执行时,jar 文件会执行除我创建的 Java 类之外不需要资源的所有操作。
我试图实现的目标可能吗?如果是这样,我如何在创建 jar 文件时保留系统的全部功能?
我将非常感谢您提供的任何帮助。
I recently completed a college Java assignment. The assignment utilised various other jar files, e.g. mysql connector. When I created a jar file from the Java programs in the project the connections to these other jar files were lost.
I tried various different combinations when creating the jar file and once included the mysql connector, but to no avail. I didn't expect this to work as my research had shown that usually only sound effects and images are classed as acceptable additional files.
Everything is within the same directory and all the classpaths to the various jar files are relative. My IDE is jGrasp. The jar file when executed did everything that didn't require resources other than the Java classes I had created.
Is what I was trying to achieve possible? If so how can I retain the full functionality of the system when creating a jar file?
I would be very appreciative of any help you can provide.
发布评论
评论(1)
您不能将 jar 文件包含在其他 jar 文件中,即嵌套 jar 文件。另请注意,如果使用
-jar
选项执行应用程序,则将忽略-classpath
选项。解决方案1:如果您想将其他jar添加到类路径中,可以编辑jar清单文件中的
Class-Path
选项。解决方案 2:如果您想将应用程序作为单个 jar 进行分发,则必须使用某些工具(例如 FatJar 或 OneJar。
相关问题:
You can't include jar files in other jar files, i.e., nest jar files. Also, note that the
-classpath
option is ignored if you execute your application using the-jar
option.Solution 1: You can edit the
Class-Path
option in the manifest file of the jar if you want to add other jars to the class path.Solution 2: If you want to distribute your application as a single jar, you'll have to merge the jar files using some tool such as FatJar or OneJar.
Related questions: