Recently familiar with the Java language, in the learning process of eclipse common operations familiar with. This article briefly introduces the creation and use of jar packages.
The jar package in Java is equivalent to the Lib library in C/s + +, it is to package the. class file, the common jar package has the API library package (^_^, this is what I invented) and the executable jar package. This article explains the creation of the API library package, as follows:
Create a new Java project JAREXP, create a new Jarexp.java file, and the source code Jarexp.java to generate the jar package is:
Package Com.lming08.data;import java.io.*;p ublic class Jarexp {public void print () {System.out.println ("class Jarexp Executed! ");}}
The process for generating a Jar package is: Right-JAREXP Project--->export---->jar File---->next----->finish
This generates a JAR package.
--------------------------------------------------------------------------------------------------------------- ----
The above is the process of generating a jarexp.jar package, and the following explains how to reference the package in other projects.
Create a new Jarimp project, and then create a new Jarimp.java file with the following file contents:
Package Com.lming08.data;import Java.io.*;import Com.lming08.data.jarexp;public class Jarimp {public static void main ( String[] args) throws exception{jarexp je = new Jarexp (); Je.print ();}}
Right-click Jarimp Project---->build path----->configure Build Path
At this time there are two options, the first is to choose Add Jars, refers to the corresponding jar package in each project in Eclipse, and the second is to choose Add External Jars, which means that the jar package can be referenced in any directory. In this article, select the first, so now create a new lib directory in the Jarimp project and copy the Jarexp\lib\jarexp.lib to Jarimp\lib\, then click the Add Jars option to select Jarimp\lib\jarexp.lib. You can then execute the JARIMP project, and the results are as follows:
Class Jarexp executed!
It is clear that the result is correct, proving that the build jar package and the reference jar package were successful!