Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link java source from other project?

Tags:

java

eclipse

I'm using the same java class in one of my main application, and in another project. This class is still in development and I therefor cannot compile it always as a jar and add it as a library.

How can I link this *.java class in another project to that it is used as if it belongs directly to that project?

I tried going to project properties > java build path > link source. I can make reference to a source folder of another project. Fine, BUT always eclipse complains about wrong package path. The strange thing is, that the shared java class in the new project is placed unter (default package) whereas I would it expect to just be displayed with the same path as in the main project. And Eclipse claims to remove the package path. If I do so, of course, the main project will complain about a missing path there.

What am I doing wrong? How can I synchronise this?

like image 835
membersound Avatar asked Oct 01 '12 11:10

membersound


2 Answers

Assuming these two projects are in the same workspace, go to the properties of the project where you want to refer to the java class and do the following:

Project Properties => Java Build Path => Projects => Add => Check the box against the project that contains the Java file.
like image 117
Vikdor Avatar answered Oct 06 '22 00:10

Vikdor


I'm a bit late with the answer, still it may be helpful to someone:

In the Eclipse:
1) right-click the destination folder -> New -> File
2) click "Advanced>>" and set "Link to file in the file system"
3) Browse, select the source file and click "Finish"
Here you are!

Still if you just share source files from neighbor-project in the workspace you may simply import them like you import any other classes:

import other.project.class;

The latter works for me, if it doesn't for you - I may look for settings.

like image 24
sberezin Avatar answered Oct 06 '22 01:10

sberezin