Eclipse link to external classes - eclipse

I'm working with Eclipse and am able to create projects, but I want to start building my own libraries.
How can I link to class/library files from outside the Eclipse environment?
lee

(Assuming you are developing Java projects with Eclipse).
Right click on your project name to display bring up context menu
Select Project properties... to display properties panel
Select Java Build Path
Select the Libraries tab
You can now add a external library in a variety of ways: A JAR that belongs to another Eclipse project, an external JAR, a directory, etc.

Related

Editing workspace source associated with jar file in same workspace

I have a project A in eclipse whose code is compiled into a jar and used by a separate project B.
I have associated the jar to the workspace project A code.
When I run project B I get stack trace on the console which references the jar.
When clicking on the references the correct file opens up from project A but as read only, I want to edit this file and fix my code.
What I end up doing is open the file manually using search typing the name or navigating to it in the package explorer and then edit it.
I mean file is there in the project in my workspace, why is it not editable?
Is there any way around it?
To open a Java file of project A with the Java Editor (editable) instead of with the Java Class Viewer (read-only) when you are in your project B, you have to do the following:
Right-click project B and choose Properties
In Java Build Path, tab Projects click Add...
Select project A and click OK
In Java Build Path, tab Order and Export move project A to the top by selecting project A and clicking UP several times
Click Apply and Close to close properties dialog of project B
I would recommend convert project A to a plug-in project. A plug-in JAR can be used in both, a plain Java and an OSGi application. The code would be more modular and changes in project A would not require a JAR file to be updated in project B.

Configure the build path in eclipse for Spring MVC Step-By-Step Tutorial

I begun this Spring MVC Step-By-Step Tutorial part 1 at 1.8 it says
"If you are using an IDE, you will want to configure your project's build path by adding the jars from the 'lib' directory. You will also want to add servlet-api.jar from your servlet container's 'lib' directory ('${appserver.lib}'). Adding these to your build path should successfully resolve all the import statements in the 'HelloController.java' file."
I add jars in the 'lib' folder but the issues does not solves. I could not figure out how to configure the build path. Can any one help. Thanks
Right-click on your project root and select Build Path -> Configure Build Path.... Select the Libraries -tab and click Add JARs.... Navigate to your projects' lib-folder and select the .jar -files, then click Ok.
Edit:
From the comment below:
can I define the library once and for every project I just mention the
path
If you have multiple projects that use the same jar-archive or archives, you can define a User library for your Eclipse-installation: Select Window -> Preferences, then Java -> Build Path -> User Libraries. Click New, give a name to your user library and click Ok. Select the User library you just added, and click Add JARs..., navigate to the jar you want to add to the library and click Ok. Note that single User library can contain multiple jars (such as all needed Spring-jars, like core, webmvc, tx...), so you can keep repeating the Add JARs... -step.
When you want to use the defined user library in your project, go to the Libraries -tab in your projects' Build Path, and click Add Library, then select User Library and click Next. Now you can pick the library from your user libraries you've defined.

How to change Liferay Portlet Plugin API library in Eclipse?

I have switched my web-application to run on another installtion of Liferay. Consequently, I was able to changle classpath libraries in my project to new server location. This includes JRE System Library and Liferay v6.0 CE. I.e, both these libraries can be added for new server location from Java Build Path dialog.
But the library "Liferay Portlet Plugin API" still refers old Liferay installation path and I see no way to change it.
How is it possible?
UPDATE 1
Here: http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+IDE+Getting+Started+Tutorial
On the very most low picture you can see all three libraries listed in Package Explorer. Two of them I was able to change and the question is about third one.
You can manually change file .metadata\.plugins\org.eclipse.jdt.core\variablesAndContainers.dat.
So open your filesystem browswer (My computer) navigate to your liferay IDE workspace location and go to .metadata\.plugins\org.eclipse.jdt.core. Open file variablesAndContainers.dat and find and edit your jars locations.
After that restart Liferay IDE or simply close and open your project.
UPDATE:
1) Take note of jars that are needed
2) Go to configure build path dialogue than go to libraries and select "Liferay Portlet Plugin API" then click Remove
3) Create folder "lib" directly in your project (not WEB-INF/lib)
4) Add jars to lib folder (from 1.)
5) Select jars and add them to build path (right click - Build path - add to build path)
Or you can crete you User libarary with those jars and than add it to build path
Additionally to chosing correct libraries in classpath dialog, one should also change "target runtime" appropriatedly by right click project and going to properties > Targeted Runtimes.
P.S. And plus one should close project and then open it again.
in my case, following instructions in this question about clearing eclipse cache (-clear option) helped, as changing liferay plugins SDK path wouldn't change the libraries' locations when adding this library to project build path...

Why cant we see classes folder of a Dynamic Web Application from Eclipse IDE?

I have created a New --> Dynamic Web Project from Eclipse IDE ,
Modified the Java Build Path for default Output folder as
Ramesh/WebContent/WEB-INF/classes
But now , Why cant we see classes folder of a Dynamic Web Application from Eclipse IDE ??
Please see the screen shot of it .
http://tinypic.com/view.php?pic=2yjvx3d&s=7
Because that's how the project explorer's filters are configured by default.
Click on the little triangle at the top right of the project explorer view, then select "Customize View...", and uncheck "Java output folders", and you'll see it.

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.