创建包含其他库文件的JAR文件 [英] Creating a JAR file which contains other library files
问题描述
我想创建一个包含其他JAR库的 JAR 文件。但是当我执行JAR时,它会出现类路径问题的错误。
I want to create one executable JAR file which contains other JAR libraries. But when I execute the JAR, it gives an error of class path problem.
如何解决类路径问题?
推荐答案
我想你可以这样试试;
I think you can try it like this;
这是一个简单的例子。首先,我们假设我们有一个项目目录,如 D:\ javademo
。在这个工作目录中,我们创建一个主类 HelloWorld.java ,thtat包含我们的其他JAR文件,如 commons-lang.jar
。现在,我们必须将我们的主类HelloWorld和commons-lang.jar存档到test.jar文件中。
Here is a simple example for you question. First, we assume we have a project directory like D:\javademo
. In this working directory we then create a main class HelloWorld.java and thtat contains our other JAR files, like commons-lang.jar
. Now, we must archive our main classes HelloWorld and commons-lang.jar into test.jar file.
首先我们必须编辑我们的清单文件,以便我们可以指定我们的类-path和main-class
是这样的:
First we must edit our manifest file so that we can specify our class-path and main-class like this:
Manifest-Version: 1.0
Created-By: tony example
Class-Path: test.jar commons-lang.jar
Main-Class: org.tony.java.HelloWorld
我们将此文件命名为 test.mf
。现在我们使用 jar
命令生成我们的JAR文件,如下所示:
We named this file test.mf
. Now we use the jar
command to generate our JAR file like this:
jar -cvfm test.jar test.mf -C ./ .
然后它将生成JAR文件 test.jar
。您可以使用此命令使用java命令运行此主类:
Then it will generate the JAR file test.jar
. You can use this command to run this main class using java command:
java -jar test.jar
这是我的解决方案。我希望它给你一些有用的东西......
That is my solution. I hope it give you something helpful...
这篇关于创建包含其他库文件的JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!