Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we call another project java class from our project in eclipse

Tags:

java

eclipse

import ...  public class TriggerJob {      String jobStatus = "";     SchedulerMetaData metaData = null;      public void rightNow(HashMap ParamMap){   AnotherProjectClass anp = new AnotherProjectClass(); anp.display();  } } 
like image 605
Mitul Maheshwari Avatar asked Jan 21 '14 10:01

Mitul Maheshwari


People also ask

How do you extend a class from another project in java?

If you want to use the sources from one project in another project in Eclipse, do not just add a class folder. Instead, define a dependency on the other project. To define that project P2 should use the sources/classes of project P1, open the project settings of P2, and go to "Java Build Path".

How do I run a different class in Eclipse?

Step 1: Open Eclipse and click File > New > Java Project. Step 2: Provide the Project Name and click on the Finish button. Step 3: In the Package Explorer (left-hand side of the window) select the project which you have created. Step 4: Right-click on the src folder, select New > Class from the submenu.


2 Answers

You can do either this way:

In the dependency you can add the other projects to your project. Right click on project -> properties -> java build path -> projects. Add your project here.

OR

Make the classes of project into jar and add it to other project

Dependencies should be added in classpath

In run time, make sure the JAR files of the referenced projects is added in class path on both the cases.

like image 103
Mayur Avatar answered Sep 22 '22 23:09

Mayur


Knowing that you using any version of Eclipse, the below steps should help you:

Step #1. Right Click => Project

Step #2. Click Project Properties

Step #3. Click on Java Build Path

Step #4. Click the Projects Tab

Step #5. Click the Add Button

Step #6. Select the Project you want to add

Step #7. Click OK button

Hopefully this help.

like image 31
TiredOfProgramming Avatar answered Sep 20 '22 23:09

TiredOfProgramming