创建jar文件时,如何将现有的类路径保留到其他jar文件中? [英] When creating a jar file how do I retain the existing classpaths to other jar files?

查看:159
本文介绍了创建jar文件时,如何将现有的类路径保留到其他jar文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近完成了大学Java任务。该分配使用了各种其他jar文件,例如mysql连接器。当我从项目中的Java程序创建一个jar文件时,与这些其他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.

我在创建jar文件时尝试了各种不同的组合包括mysql连接器,但无济于事。我没想到这会起作用,因为我的研究表明,通常只有声音效果和图像被归类为可接受的附加文件。

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.

所有内容都在同一个目录中各种jar文件的类路径是相对的。我的IDE是jGrasp。 jar文件在执行时会执行除了我创建的Java类之外不需要资源的所有内容。

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.

我试图实现的是什么?如果是这样,在创建jar文件时如何保留系统的全部功能?

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.

推荐答案

您不能在其他jar文件中包含jar文件,即 nest jar文件。另请注意,如果使用 -jar 选项执行应用程序,则忽略 -classpath 选项。

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.

解决方案1:您可以在jar的清单文件中编辑 Class-Path 选项如果你想将其他jar添加到类路径中。

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.

解决方案2:如果你想将你的应用程序分发为一个jar,你就是将不得不使用某些工具合并jar文件,例如 FatJar OneJar

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.

相关问题:

  • Easiest way to merge a release into one JAR file
  • how to use one jar that depends on another jar

这篇关于创建jar文件时,如何将现有的类路径保留到其他jar文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆