Generation and use of jar packages in eclipse

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.