Eclipse - why cant it integrate jars in lib folder into project? - eclipse

I manually copy needed jar files into my project lib folder. Then, I try to add them to build path via "configure build path option". If i choose "add jar", then the lib folder does not show up in the "to choose from" list. So, I am forced to use "add external jars" option instead. But, that option does not make the jars a part of the project even though they lie in the lib folder. After I restart eclipse 2-3 times, the jars are magically integrated into my project.
Why is eclipse behaving this way ? Why can't I do this easily ?
Please help me.

By default, Eclipse dose not detect file change which come from outside, like copy a jar file in lib folder manually.
So after you copied jar files, you have to refresh the project by pressing F5 while selecting your lib folder. I believe that's why eclipse cannot found your jar files.
If you want to solve this problem once for all, you can active "Refresh using native hooks or polling" via
Window -> Preference -> General -> Workspace
However, this might slow down Eclipse if you have a big project with many many files.
UPDATE
As Bananeweizen mentioned, instead of doing all the copied from outside of Eclipse, you can also copied those file into Eclipse, Package Explorer View for example. This way Eclipse will detect and refresh folder automatically.

The way I was taught to add external jars to an eclipse project is to drag the jar file from explorer into the lib folder in eclipse and then on the dialogue eclipse responds with is choose the copy to option and eclipse imports the jar file and copies it to the lib location at the same time.

Related

Why do projects that I add to my 'workspace' folder don't show up? [ECLIPSE]

I am using Eclipse Indigo, and after having successfully extracted my project folder into my Eclipse workspace, it does not show up in the package explorer. I tried refreshing eclipse and restarting it, to no avail. I am 100% certain my eclipse is using the right directory and the project is in it.
What could be the problem? Thank you.
EDIT: "import projects into workspace" worked for me, but why was that necessary?
Files in the directory are not automatically picked up by the package explorer. You need to import them.
Try using the File > import, then choose
Existing Projects into workspace.
There is a checkbox that says "Copy projects into workspace" which copies it to your workspace if it happens to be in a different folder. If you start with your files in another folder, you'll see how it's copied and set up with configuration files in your workspace directory.
To answer the question, "why is it necessary to import?" you have to realize that the Eclipse workspace is just a logical container for projects, not necessarily the physical container for them.
Also realize that a directory of project-related files does not make an Eclipse Project; Eclipse must be given or generate it's own set of configuration in order to understand a project (minimally, for Java projects, .project and .classpath). Without those, Eclipse has no idea what to do with an arbitrary folder that you call a "project." That's what the Import or Create Project wizards are doing under the covers, generating those config files.

Eclipse IDE -- how do I put my external .jar files into a lib folder?

Eclipse IDE - Can someone please tell me how I can group my external .jar files into a C:\lib folder? I'd really like have them all in a lib folder and not taking up vertical space in the root of my project (see attachment).
I have read some of the similar posts here and tried them but my projects still are not 'seeing' the needed .jar files! It's very frustrating.
I know how to add a Folder but how do I tell Eclipse my .jar folders are in c:\lib so my projects will execute? I'm not even sure if making a lib folder in my project is even related to the fact that my jar files happen to be in c:\lib.
Thanks...
(source: msgVault.com)
From your description it sounds to me like you want the jars to stop taking up space in the root of your project. I am not sure how you initially added them but if I am adding external jars this is what I usually do:
Right click on your project, select properties, then Java Build Path, and then click the libraries tab, click on add external jars and then you can select each one individually (which would be a pain) or you can select them all at once if they are in the same folder (hence the c:/lib). Click OK and it should add them into a Referenced Libraries folder like so:
Also, when you open the libraries tab initially, if all of your jars show there, remove them before proceeding as you don't want to import them twice into your application (If that's even posssible, not sure).
Edit
Switch to Package explorer:
Click on Window > Show View > Package Explorer
Update
If you want to add c:\lib to your project do this:
Right click on your project, highlight build path, click Add Libraries..., in the list select User Library, click Next, click User Libraries... on the right. A new window will open. Click New... and then give the library a name such as "clibs". Click OK and then highlight the new library and click add external jars. Select the jars you want from c:/lib and then click OK. Now you can add that User library to any application you want and it will not "pile" up in the root directory under Project View.
That is just eclipse's way of displaying what libraries are on the build path of the project. It doesn't mean that they are on the root of the project, those are just references to those jars ( that maybe any-where on the system ).
A good practice is to get all the jars required by your project and put them in a folder. Next, you can either declare that folder as a library from eclipse and add that library on your build-path or you can just add the jars directly. But they will still be displayed like you are seeing them already. The true path of where these jars are located will be written next to them (like you can see in the attachment C:\selenium....).

Eclipse jar file is not exported with project

I have a simple project that I need to be very easily imported into eclipse and started. When I export my project and import it again it comes with an error saying it is missing a required jar file. This jar file is added to the build path, but does not carry over when the project is exported. Why is this? I have been searching all day for an answer on Google and none have helped.
Would I just have to send the jar file along with the project and have the users manually add it?
Things I have tried:
Going into build path order and export and clicking the jar file.
using a clean workspace for the import / restarting eclipse.
For anyone with a future problem like this one. I was putting the jar in the lib folder and also adding it to my build path, but the jar would not export over. When I added the jar to the WEB-INF / lib folder it successfully carried over with the export.
You may want to try this:
Right click on the imported project select Build Path -> Configure Build Path -> Java build Path -> Libraries Tab and check if the jar file which eclipse says missing is present in the Libraries tab.
If it is present then select it and click Edit, a "File dialog" will pop up, find the desired jar which is in your computer's directory. and click Ok then wait for eclipse to build
the workspace. If it is not present then add it through Add JARs... or Add External JARs...
Export it as an Archive file of the project rather than a jar. Then it's just a matter of someone else importing it as an Existing Project. Exporting it as a jar is only something you do when you want to deploy the jar and run it.

Should renaming a project in Eclipse also rename project folder on file system?

Should renaming a project in Eclipse also rename project folder on file system ?
My project file system name remains the same even when I rename the file on Eclipse.
Should I manually rename the project on the file system to same on Eclipse ?
It appears that renaming a project will only rename the underlying filesystem directory if the project was created with the "Use Default Location" checkbox selected (meaning the project is created in the workspace directory). If you create a project and specify a custom location outside the workspace, renaming that project in Eclipse does not rename the project's host directory. In that case, you'll probably want to:
Rename the project in Eclipse (which will update any internal references and the .project file)
Remove the project from your Eclipse Workbench view (making sure that the "Delete file contents" option is NOT selected in the delete confirmation dialog).
Rename the project's directory in your filesystem.
Import the project back into your Eclipse workspace.
I was surprised to learn this (I tested it with Eclipse 3.7), but it seems to be logical to me. The idea is that projects in the workspace folder are considered to be "under Eclipse control" as opposed to projects that are located in arbitrary places on your filesystem.
Use Refactor to rename the project name. It will rename the file/folder in filesystem as well.
Menu -> Refactor -> Move... (Shift + Alt + V).
In this window you can change name of the folder name and also change the path completely.
If the folder name is important, then change it manually. Keep in mind that you will have to re-open or re-import the the project into eclipse. After you rename the folder, Eclipse won't know where to find it.
In Eclipse Oxygen (4.7) the Move option is greyed and renaming the project does not rename the directory. However, if you switch to the Navigator view (may need to find it under Window > Show View > Navigator) the Move option will be available and it will rename the project's directory.
This is a lot faster than having to recreate the project or re-import it.
If your project is a Maven project to rename, do steps as followed:
Open Context Menu on your project > Refactor > Rename Maven Artifact.
Change Group or ID.
Check "Rename Eclipse project in Workspace".
press OK button.
Update maven project by Context Menu > Maven > Update Project.
Using eclipse Neon 4.6.3, renaming does not work. You will have to do what E-Ritz said in his answer.
It is also worth mentioning that if you are importing a project as a Maven project (via Import... -> Existing Maven Projects), the project name will be taken from the pom.xml rather than the folder. So you should also change the <name>my-project-name</name> part of the pom

Import Libraries in Eclipse?

I just recently downloaded the dom4j library, but for the life of me I have no idea how to access it. I dropped it in the plug-ins folder and rebooted Eclipse, without success. For some reason finding a straight answer for this is more difficult that I thought it would be.
No, don't do it that way.
From your Eclipse workspace, right click your project on the left pane -> Properties -> Java Build Path -> Add Jars -> add your jars here.
Tadaa!! :)
Extract the jar, and put it somewhere in your Java project (usually under a "lib" subdirectory).
Right click the project, open its preferences, go for Java build path, and then the Libraries tab. You can add the library there with "add a jar".
If your jar is not open source, you may want to store it elsewhere and connect to it as an external jar.
For the Android library projects, I do it as in the attached screenshot:
Right click the project, select Properties->Android and in the library section click Add. From here you can select the available libraries.
If you are importing a jar file, then importing them as jar or external jar, as other posters posted would work. I prefer to copy/paste jar file in the libs folder (create one if it doesn't exist) and then import as jar.
If you want to get this library into your library and use it, follow these steps:
You can create a new folder within Eclipse by right-clicking on your project, and selecting New Folder. The library folder is traditionally called lib.
Drag and drop your jar folder into the new lib folder, and when prompted select Copy Files.
Selecting the Project tab at the top of the screen, and click Properties.
Select Java Build Path followed by the Libraries tab.
Click the Add JARs… button and select your JAR file from within the lib folder.
Your JAR file will now appear in both the lib and Referenced Libraries folders. You can explore the JAR's resources by clicking Referenced Libraries.