I understood that eclipse generates a runnable jar file with all library .jar files extracted and included in the jar file. How do I do the similar this while creating a jar file manually from command prompt. Do I need to extract all the lib jars into classes folder?
我知道eclipse会生成一个可运行的jar文件,其中提取的所有库.jar文件都包含在jar文件中。从命令提示符手动创建jar文件时,如何执行类似操作。我是否需要将所有lib jar提取到classes文件夹中?
Currently I am using -
目前我正在使用 -
jar cvfm example.jar manifest.txt -C Classes/ .
Which creates a jar file with all the class files and I need to have all the library jars in the same folder as this example.jar exists.
这会创建一个包含所有类文件的jar文件,我需要将所有库jar放在与此example.jar相同的文件夹中。
1 个解决方案
#1
3
there's no way do this kind of thing from the jar command line utility. there are 3 main solutions to the dependencies problem:
jar命令行实用程序没办法做这种事情。依赖问题有3个主要解决方案:
- in your MANIFEST.MF you may reference other jar files as part of your classpath and then people could invoke your code using
java -jar [just your jar]
and your dependencies will be picked up - 在您的MANIFEST.MF中,您可以引用其他jar文件作为类路径的一部分,然后人们可以使用java -jar [只是你的jar]调用你的代码,你的依赖项将会被选中
- you can package your code and dependencies into a fat jar (which is what youre describing). usually you just convert your project to use some build tool (more advanced than simple javac and jar) and configure the tool. for example with maven. see 2 different approaches here and here
- 你可以将你的代码和依赖包装到一个胖罐子里(这就是你所描述的)。通常你只是转换你的项目使用一些构建工具(比简单的javac和jar更先进)并配置工具。例如与maven。在这里和这里看到2种不同的方法
- (again with a build tool) you can use something better than a fat jar - use one-jar. the difference is that with a fat jar you run the risk of files with the same name in different libraries "colliding"
- (再次使用构建工具)你可以使用比胖罐更好的东西 - 使用一个罐子。区别在于,使用胖罐会冒不同库中具有相同名称的文件“碰撞”的风险
#1
3
there's no way do this kind of thing from the jar command line utility. there are 3 main solutions to the dependencies problem:
jar命令行实用程序没办法做这种事情。依赖问题有3个主要解决方案:
- in your MANIFEST.MF you may reference other jar files as part of your classpath and then people could invoke your code using
java -jar [just your jar]
and your dependencies will be picked up - 在您的MANIFEST.MF中,您可以引用其他jar文件作为类路径的一部分,然后人们可以使用java -jar [只是你的jar]调用你的代码,你的依赖项将会被选中
- you can package your code and dependencies into a fat jar (which is what youre describing). usually you just convert your project to use some build tool (more advanced than simple javac and jar) and configure the tool. for example with maven. see 2 different approaches here and here
- 你可以将你的代码和依赖包装到一个胖罐子里(这就是你所描述的)。通常你只是转换你的项目使用一些构建工具(比简单的javac和jar更先进)并配置工具。例如与maven。在这里和这里看到2种不同的方法
- (again with a build tool) you can use something better than a fat jar - use one-jar. the difference is that with a fat jar you run the risk of files with the same name in different libraries "colliding"
- (再次使用构建工具)你可以使用比胖罐更好的东西 - 使用一个罐子。区别在于,使用胖罐会冒不同库中具有相同名称的文件“碰撞”的风险