更新时间:2023-09-19 12:53:16
我觉得你可以这样试试;
I think you can try it like this;
这里有一个简单的例子来回答你的问题.首先,我们假设我们有一个像 D:javademo
这样的项目目录.在这个工作目录中,我们然后创建一个主类 HelloWorld.java 并且它包含我们的其他 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.
首先我们必须编辑我们的清单文件,以便我们可以指定我们的类路径和主类像这样:
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...