1. Create Project project1
2. Create the class file classa
[Java]
View plaincopyprint?
- PackageCom. test;
- Public ClassClassa {
- Public StaticString getclassa (){
- Return "Classa data";
- }
- }
Package COM. test; <br/> public class classa {<br/> Public static string getclassa () {<br/> return "classa data "; <br/>}< br/>}
3. Right-click and choose "Export"> "JAR file" under "Java"> "Next"> select the class file to be included in the package,
JAR file directory select the Save location and enter the JAR file name (D:/temp. Jar) --> finish
4. Create a Project
5. Right-click projectb --> properties --> JAVA buil path --> libraries --> Add externel jar --> select D:/temp. jar --> OK
6. Create a file classb
[Java]
View plaincopyprint?
- package com;
- Import com. Test. classa;
- Public class classb {
- Public static void main (string [] ARGs) {
- system. Out. println (classa. getclassa ();
- }
- }
Package com; <br/> Import COM. test. classa; <br/> public class classb {<br/> Public static void main (string [] ARGs) {<br/> system. out. println (classa. getclassa (); <br/>}< br/>
In this way, you can
You don't need to package the classes that you want to reference other projects.
Projectb --> right-click --> Property --> JAVA buil path --> projects --> Add --> select projecta --> OK
Respect others' labor achievements. Please refer to the post for self-conversion.
Http://blog.csdn.net/swandragon/archive/2009/10/13/4665283.aspx