Use myeclipse to make the jar package so that it contains the pointer to the dependent jar package

Step 1: Create a directory and copy all dependent JAR packages to this directory. For example, my test project depends on two JAR packages: classes12.jar and log4j-1.2.14.jar

 

 

The second step: write the program, it is no problem to write first, I only wrote one class, with the main function, the package name is test: test.Main

 

Main.java

 

Java code   Favorite code
  1. package test;  
  2.   
  3. import org.apache.log4j.Logger;  
  4.   
  5. public  class  Main {  
  6.     private Logger log = Logger.getLogger("R");  
  7.       
  8.     public Main(){  
  9.         log.debug("********************");  
  10.     }  
  11.     public static void main(String[] args) {  
  12.         Main m = new Main();  
  13.     }  
  14. }  

 The above sample program does not use classes12.jar, but depends on classes12.jar just to demonstrate the dependency addition of multiple jar packages

 

third step:

 

Start typing the jar package as shown:

 

The MANIFEST.MF file generated after that has only two lines:

Manifest-Version: 1.0

Main-Class: test.Main

 

 

In this case, you need to manually modify this file to:

Manifest-Version: 1.0

Class-Path: classes12.jar log4j-1.2.14.jar

Main-Class: test.Main

 

Note that a line has been added. In the Class-Path line, the name of the dependent JAR package is written, separated by spaces. If there is a subdirectory, write the relative directory, which is the relative path relative to the batch file.

 

Then repackage and export the JAR, as shown in the figure:

 

 

There is no need to modify MANIFEST.MF when you type this jar package again in the future, but if you add a dependent jar package, you only need to manually write the dependent jar package name in this file and save it. The executed jar package no name

 

Step 4: Write the batch

 

File name: run.bat

content:

java -jar TestJar.jar

 

Final directory structure:

 

Step 5: Test

 

Run cmd and execute in sequence:

d:

cd temp / TestJar

run

 

Needless to say

 

 

URL:http://stride.iteye.com/blog/1350156

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326344230&siteId=291194637