简体   繁体   English

在Linux中创建jar文件时如何包含外部jar文件?

[英]how to include external jar files while creating a jar file in linux?

I have an external jar file mysql-connector-java-5.1.26 under /Users/remy/Downloads/mysql-connector-java-5.1.26/mysql-connector-java-5.1.26.jar . 我在/Users/remy/Downloads/mysql-connector-java-5.1.26/mysql-connector-java-5.1.26.jar下有一个外部jar文件mysql-connector-java-5.1.26。 I want to create a jar file from hello.java which should include the external jar file as specified as well, where hello.java is dependent on the external jar file. 我想从hello.java创建一个jar文件,该文件还应包括指定的外部jar文件,其中hello.java依赖于外部jar文件。

Users
  -->remy
      -->Downloads
               -->mysql-connector-java-5.1.26
                                          -->mysql-connector-java-5.1.26.jar
Users
  -->remy
      -->Documents
               -->Hello.java

How to create the myManifest.txt and include the external jar file so as to compile and run them together? 如何创建myManifest.txt并包括外部jar文件,以便一起编译和运行它们?

There are two ways. 有两种方法。

  1. Create a MANIFEST.MF that refers to the other jar in its classpath 创建一个MANIFEST.MF,它引用其类路径中的另一个jar
  2. Whenever you run the program, make sure you include both jars in your classpath. 每当您运行程序时,请确保在类路径中都包含两个jar。

That said, I think you should go back and read a tutorial because you've made a few mistakes in your question. 就是说,我认为您应该返回并阅读教程,因为您在问题中犯了一些错误。

  • "hello.java" is not a jar file as you've said. 正如您所说的,“ hello.java”不是一个jar文件。 This is a java source file. 这是一个Java 文件。 It will be compiled into a class file. 它将被编译成一个文件。 You can take this class file and put it in a jar file. 你可以把这个文件,并把它放在一个jar文件。
  • You can't name your manifest file "myManifest.txt" AFAIK. 您无法将清单文件命名为“ myManifest.txt” AFAIK。 It has to be named something specific and be located in a specific place. 它必须被命名为特定的东西并位于特定的位置。 Read a tutorial to see the details on that. 阅读教程以了解其详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM