How to import one Eclipse project as a library into another? - java

I would like to use one of my eclipse projects in another one. Is there a 'smooth' way to do that, without having to export one as a jar file and importing it into another? Especially since I work on both project simultaneously, I would like the latest changes from the imported project to be automatically built and imported into the other one. Is that possible?

It is possible. Right click on your project -> Build Path -> Configure Build Path. Switch to the Projects tab and add one. It will work as a library.
P.S. You might also want to check this: Creating a java library with Eclipse

Answer to this question explains how to import your own library in eclipse.
Quoting from the answer.
Just have "Project" reference your "Library", on windows the process
is (using menu / tab names)
Go to: Project -> Properties -> Java Build Path -> Projects
Client Add...
Select your "Library" project from the list
Click Ok
Click the other Ok Now your done and you can use import for classes in your "Library"

Related

JavaFX Eclipse suggestion to import not present

I am just starting with JavaFX and for some reason, Eclipse does not suggest to import JavaFX stuff so I have to type it in manually. Example: javafx.scene.Group I typed in Group as a type and it suggested other things such as javax.swing.GroupLayout.Group
image of suggestions
I'm not exactly sure, but I think maybe the fact that the JavaFX library is under Modulepath instead of Classpath has to do with it, but it only works if it is under Modulepath.
Help would be greatly appreciated, thanks!
I'm rewriting this answer, as #kleopatra pointed out it was inexact
For suggestions to work, you need to have JavaFX on your project's build path.
If you've created a plain Java project in Eclipse, with a module-info.java at it's source path root, then you need to add all the required jars to the module path:
JavaFX SDK should already be installed on your system, or download it from Gluon and unzip it
Right-click your Java project, got to Build Path -> Configure Build Path...
Go to Libraries tab, point to the Modulepath section
Click [Add External JARs...] button, pick all the jars from JavaFX SDK, hit [Apply and close]
Then suggestions should work as expected, and imports will be automatically inserted at the top of your java files, but they will appear in error the first time you import anything from a given library module, as this module must also be required in your module-info.java. You can do that automatically with a quick fix ("Add 'requires javafx.something' to module-info.java") when hovering the import.
Now there's a more straightforward way to create a JavaFX modular project in Eclipse, using Maven:
Create a new Maven Project
Check and pass the first wizard screen
Select archetype org.openjfx:javafx-archetype-fxml
On the next screen, you can select the JavaFX version of your choice (currently 13 by default)
After the wizard terminates, you've got a nice little project already setup with an application window and two FXML sample displays. You can start from there to build your own project.

What is the "right" way to add libraries on Netbeans?

I'm a using Netbeans 8.1 to code in Java, when I want to add an external library (such as XStream, JDateChooser, etc) I find the .jar online and I add it to my project through the right clicking in Libraries --> add JAR/Folder.
After this I write my code and everything works fine until I finish my project and I want to export it into a .jar with Clean and Build
I think this maybe because I give an absolute path to the libaray instead of a relative one but I'm not sure.
PS: The library that I'm having trouble with is XStream 1.4.7
All the libraries included should pack in a jar file after build. The simplest approach is to click right on your project, select Properties and The project properties. In the new window opened find Categories and Libraries. The in the right side you may see the button Add library/JAR. Probably it's the same way.
Also you can create a Maven project and import all the libraries through dependencies.

having issue with eclipse library

I am new to Droid development using Eclipse. I am trying to use PinnedSectionListView found here: https://github.com/beworker/pinned-section-listview
What I need to understand is how do I import that into my project? Do I need to load the project and create a .jar? I thought to use libraries like the one here it needed to be a .jar lib. I am a bit confused on how to use github libs like that. Also, not a big deal, I am fluent in c/c++/c#/objective c, but I am new to java. Code I can handle, eclipse ide, jar files, etc. not so much.
Any steps would be helpful, or a pointer to an example. Thanks for any help.
You have to download the library folder! Then import it in your Eclipse from the File menu! After you have done this, you have to right click your project and reference the imported library as a library project in your original project!
http://www.androidbegin.com/tutorial/implementing-actionbarsherlock-in-android/
This is a link for another library but the steps are the same.
Download and unpack the zip file
In Eclipse's Package Explorer, right click and select "Import..."
In the Import dialog, select "Existing Android Code into Workspace"
Select the dir of the unpacked file, and click "Finish", the library is now part of your workspace, which leaves the last thing to do:
Right click on your primary project and select "Properties", in the Properties dialog, select "Android" in the left panel, then click on "Add" button on the right side of the panel, select the library, click "Ok". Now you are ready to use its classes and resources.

How to backup a User Library in Eclipse?

I have 100+ jars in a project. I have manually defined the source jar location for most of them so that the javadoc becomes conveniently available within the IDE.
Now, if I have to configure the IDE on a different machine, I don't want to go through the whole process again.
Can I backup the User Library definition and import it in another instance of Eclipse?
Workarounds are welcome as long as they make javadoc available within Eclipse and don't require repeated manual work of linking source jar for each jar.
In Eclipse Select Window -> Preferences. In Preferences Dialog select Java -> Build Path -> User Libraries. In the right side list select your library and Export it.
Consider to use a tool such as Maven to manage your dependencies.
Window -> Preferences
Java -> Build Path -> User Libraries -> buttons Import and Export

Eclipse: "The import java.io cannot be resolved"

I have several Android projects in Eclipse, and all is fine, except one (a library) that can not resolve any imports.
The java.io imports do resolve fine in other Android projects in the same workspace, and previously (I haven't used it for over a year) this library worked fine, too.
Any ideas?
Check two things
Eclipse preferences
Check your Eclipse preferences: Java -> Installed JREs
The one that you're using should be marked and it should be a JDK not just a JRE.
Project build path
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the libraries folder whether the JRE System Library is present and ...
If not add it using Add library -> JRE System Library and then
select the correct one (from an installed JDK).
I am using Maven an this is what I did to re-solve -->
Right click on project
Maven -> Update Project. Make sure you choose 'Force update of Snapshots/Releases'.
Also check the 'clean project', 'update project conf from pom' and 'refresh workspace resource options' and click ok.
The following worked for me:
Close the project and reopen it.
OR
Clean the project ( = rebuilds the buildpath and thereby reconfigures the JDK libraries).
I was missing the JRE Systems Library in my Project Tree.
And navigating to Projects' Build Path and 'Add(ing) Library' worked!
I just ran into this problem with Eclipse 2022-6 and java-17-openjdk-amd64. I just appeared during editing in another file, the same code had worked before.
For me, all settings were correct and none of the above tricks worked. What I then did was completely removing the import command import java.io.Closeable;, saving the file, adding the same import command back at the same place, and saving again. The error disappeared.

Categories