Eclipse - Importing your own library - java

Okay, hopefully this is quick and easy.
I have two separate java projects, 'Library' and 'Project', and I have a class in 'Project' that wants to implement a method found in 'Library'. I am looking for some kind of 'import' call to make at the top of my 'Project' class, to make the methods found in 'Library' accessible in that project.
How would I do that?
On another note, this 'Library' project only exists because I want to use a number of classes of my own to supplement the the usual java libraries (java.util, java.io, etc...). Is there a way I can add my java project to my java libraries? (ie. 'import java.Library.className;')
Thanks,
Jonathan

Just have "Project" reference your "Library", on windows the process is (using menu / tab names)
1. Go to: Project -> Properties -> Java Build Path -> Projects
2. Client Add...
3. Select your "Library" project from the list
4. Click Ok
5. Click the other Ok
Now your done and you can use import for classes in your "Library"

There are several ways:
A. Import source files
Right click your project in the project explorer
select
Properties-->Java Build Path
Click on the Source tab and the Link Source button and add the root folder containing Library and click Finish
Now click on the Projects tab and click the Add button to add your 'Library'. Click Ok and you're done
B. Import Jar
When you compile your eclipse project it creates a jar for your project in the 'Build' subfolder of the root directory of your project. To import that in you current project:
Again Right click your project in the project explorer
Select Properties-->Java build Path
Click on the Libraries tab and click Add External JARs. Navigate to the folder containing Library.jar and click Finish and click Ok
You should now be able to import your names from your Library Project

Related

How to add project of different workspace into the current workspace in Eclipse

I have two workspaces and I want to use java file as a parent class or you can say extends it from workspace2 to workspace 1 in eclipse, how can I do this?
As I can add project from same workspace but unable to figure out from different workspace.
I dont want to import the project.
Thanks in advance
You can make New File -> advanced options and Link to Folder in the system where the class is
You need to import your project from workspace 2 to workspace 1.
You can reference your project in another workspace in the build path configuration of your project, linking two eclipse project, even if they are in different workspaces.
If you want the code to be available for changes this are your options:
You have to either import the project or create a new workspace that includes them all.
Note that you may extend the java class from the same project or from another project within the workspace, but not from another workspace.
If you are willing not to have the code in front of you available for changes, you may build the first workspace' project into a jar and then use that as part of your other workspace.
Way 1
You can add the second project's src folder to the current project and you can add them in your project.
Right click on project -> Build path - > source tab - > link source
Way 2 :
Make that external project as a jar and add as a dependency.

Using a project's package in another project in eclipse

how can I use the classes of a package out of the main project where it has been defined?
for example imagine there is an Employee class in package people which belongs to ProjectOne. let's assume Employee is needed in another project (ProjectTwo) with the same features.What should I do there?
Right-click on ProjectTwo in the Package Explorer. Go to Build Path -> Configure Build Path. Go to the Projects tab, click Add, select ProjectOne, and click OK, then click OK again to exit the project properties window.
Then import your classes as usual - within ProjectTwo, you should be able to see ProjectOne's classes as if they were in the same project.
Since i dont know wich eclipse your using i tryed this on eclipse kelpler
you can Drag packages into the other Projects src folder to use them

How to create two projects in eclipse to point to one source folder

I have multiple project source which I checkout from SVN and put in project one
I want project two to point to specific part from these sources and
project three to another part of the sources from this multiple project.
How can I do that in eclipse ?
So when I make a change in project two, when say SVN synchronize on project one to see that the sources have been changed.
PS. I use gradle and for me it is much easier to build only one subproject, not the whole tree every time and ofcourse to see Eclipse Ctrl+space helps.
Right click on project two, and left click on Properties.
Left click on Java Build Path. Left click on Add Class Folder.
Check the class folder (bin) from project one. Left click on OK.
Back on the Java Build Path dialog, left click on OK.
Go to your second project's properties, to Java Build Path, then to the Source tab, and click on Link Source... button. There, click on Browse... button and select the src folder of your first project. This will allow you to change the source files from either project, and compile them from either project as well.

How to reflect another project's class info

there are two projects in eclipse! how to reflect one class in other project? I put other project's class path into system's property. but still popup class not found exception. Is there any good solution for it?
System.out.println(System.getProperty("java.class.path"));
System.getProperties().put("java.class.path",
System.getProperty("java.class.path") +
";C:\\Users\\fu.jian\\workspace\\Study\\bin");
System.out.println(System.getProperty("java.class.path"));
Class<?> forName2 = Class.forName("study.Activator");
System.out.println(forName2);
Right click the project to bring up the context menu.
Build Path->Configure Build Path
Under the Java Build Path dialog, select the Projects tab and add the project.
Try to add the project B to classpath of project A by:
In Eclipse click on project A -> mouse right click and select Properties -> Select Java Build Path -> Select Projects tab -> Click on Add... and check project B
The problem will be resolved inside Eclipse, if you use external tools for compilation and building the project - your problem will still appear.
You can export the project B as jar and copy the jar into the project A libs. This way you won't depend on Eclipse.

importing org.apache.commons.math.stat.StatUtils eclipse project

I am wanting to use the StatUtils in a project i am working on. How do i get the ability to import that package in my eclipse project?
Thanks
Right click on your project, then a menu will be showed, choose "Properties", click "Java Build Path" and choose "Libraries" tag, you can click "Add JARs..." or "Add External JARs..." to add the package you want.
You can refer to the website : http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
I guess this is the 2 option ^^
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-114.htm -- good eclipse tutorial!
GL.
Point your browser to http://commons.apache.org/math/. Then read the instructions. Most particularly, download the jar file from the download area, and then add that jar file to your project's build classpath in the Eclipse build path options for the project.

Categories