How to put eclipse jdt jar libraries in Java Build Path? - java

I'm trying to use eclipse jdt, and I tried to import related modules in java source file.
I have a bunch of errors as the jdt libraries are not in Java Build Path.
I tried to open Add Libary -> Plug-in Dependencies, but it doesn't have the jdt jar files.
I could use Add External JARs to point to all the jar files, but I don't think it's a good idea considering I have to do the same thing over and over again with new projects.
In this case, how to put eclipse jdt jar libraries in Java Build Path? The java.util.Collection is found automatically. I guess there might be some easy way to setup so that jdt jar files are found automatically.

Assuming your project is an eclipse plugin project you can add the jdt as a dependency and the jars will be automatically added to the plugin dependencies

Normally, I had to use eclipse plugin for using jdt for accessing the files in the workspace, and getting the jar files and such.
However, I found this solution to be very useful for using jdt/ask. The idea is to use string as an input to the jet, and import the related jars for using the jdt APIs.
http://www.programcreek.com/2011/01/a-complete-standalone-example-of-astparser/
I had to open Configure Build Path.
Then, I could select and import all the jar files that I downloaded from the site.
Now, I am ready to use the libraries.

In you Java Build Path screen, you notice two bottons Add Variable and Add Liberary below Add External Jars. Use those options and define a new variable or new user library; Once done, add the same in the project build path.
For newer project, you can simply reuse the variable/user library.
java.util.Collection is found as it is added as library in your build path(see first item in your screenshot). I am suggesting to do the same by introducing an User Library.

Related

How do I permanently add JARs to Eclipse?

I am using Eclipse Mars 4.5.1. I have a collection of Apache Batik SVG 1.7 JARs that are used by my projects. Rather than repeatedly importing the same JARs to each individual project now and in the future, I want to import the JARs permanently into Eclipse.
I am guessing that the best way to do that is to import the JARs into the Java System Library (eclipse/jre/lib) which is imported into every Java project by default. Is that right? How can I do this?
I don't recommend to do this. Don't add third party jars to system library. System library is not supposed to store them, and they will be exposed to all projects and apps. There is a user library concept for this.
A user library is a set of JAR files. A user library can be added to a projects build path through the build path properties page. The User Libraries preference page allows to define, edit, import, export, or remove user libraries.
Once you create a user library, it can be added it to any of IDE projects.
But it is not a good approach to dependency management to tie dependencies to IDE and/or environment. Better use dependency management and build tools as Ivy, Maven, Gradle.

Eclipse java libraries

I'm kind of new to Eclipse and I'm hating it so far
The question is I'm working on a small project with some classmates, we are using Eclipse and Git but every time someone does an immport all the libraries are lost because they are referencing the computers path like C:/someone/something.jar and then someone else push something to github and the libraries path C:/someone2/somthing.jar
Every time, I and my partners have to search for the libraries on our pc so the errors stop appearing.
Is there an easier way so we don't have to lose time searching for the libraries on our pc?
You need Java build tool like Maven, Gradle to manage your dependencies.
In that way, it will resolve the libraries for you. And in the source code, you should not check in .classpath,.project meta files. Those files should be added into .gitignore to avoid commit.
To import projects into IDE (Eclipse in your case), Maven and Gradle can help you to generate those IDE meta files. Or some Eclipse plugins could be used to import maven or gradle project.
You should create a folder for libraries and put all jar files in there, add these files to classpath using Java Build Path Option from project properties. Also add this folder to git

Eclipse IDE- Add jar? Add External jar? Add Library?

I want to integrate TwitterAPIME to my Blackberry project. I have 3 Jar files provided by TwitterAPIME. I am not sure how to link these 3 Jar files to my project.
My basic doubts are
What is an External Jar ? What is a Library ?
What's the difference between Adding jar, Adding External jar or Adding Library ?
What is an External JAR?
External as the name suggest is a Jar file that is not built by the currently developing code. It is a utility Jar file that is added externally for extra features. It could be an API Jar file provided from the external site, just as in your case the 3 Jar files will be going to call External Jar Files.
To add an External Jar file in Eclipse, follow these steps: Right Click on Project -> Select Build Path -> Select Configure Build Path -> Library Tab in the following Dialog box.
What is a Library?
A Library is a in-built Jar file from the JDK Directory or any other software e.g. J2ME-Polish as you can see in the Image above. Normally these Library files are developed by a manufacturer.
What's the difference between adding JAR, Adding External JAR, and Adding Library?
Adding Jar File: When you have more than one project in Eclipse and you add another project's Jar file, that is called adding Jar File. There is a first Button in the Photo above, it only allows you to add Jar file from the other Project.
Adding External Jar: When you add any API Jar file provided by the site or another manufacturer. In your case the 3 Jar files are External Jar Files. You can add then by using second Button "Add External JARs".
Adding A Library: Clicking on the 4th Button will open a dialog box as below.
You can add different libraries installed on your system. You can also add your own Library, by selecting "User Library".
JAR: A JAR File in your workspace.
External JAR: A JAR File in your file system. Use it for test purposes only, otherwise your project would be quite untidy.
Library: Built-in libraries such as JUnit. You don't need to know their location, these come with Eclipse.
In addition to the excellent answer given above by Lucifer, I recommend that people looking to develop or use Libraries, review the following BB supplied KB article:
Working with Libraries - shared, bundled, releasing, and using 3rd Party SDKs
Where the API is available as source or a Jar, I have found it significantly easier to include the source directly in the application. For example, in this case, rather than include the TwitterAPIME jar, you could include the TwitterAPIME source as a separate project in the application. As well as being easier to build, this can help in debugging or at least understanding issues with the API.
You might also find this sample, and in fact the containing Thread, useful:
Twitter + Facebook Sample Integration
Also building on Lucifer's answer, I have used "User Libraries" to bundle jars that are used across projects and dependent on a 3rd party service. Specifically, in my case, JMS jars. If I upgrade to a new JMS, or a different provider, etc, I can simply change the jars in my User Library and all projects referencing this are updated. Rather than changing jar dependency in every project.
An external Jar is a Jar in a path outh of your Eclipse environment: i.e. outside of both Eclipse jars and projects generated jars.
A libraray is a collection of jars prepared by someone for you.
You can cerate a User Library by selecting a group of external jars: that is useful if you have a group o jars that should logically work togehter.
A further advantage of creating a library is that you can "reuse it's definition" by referencing it in multiple projects.
Use:
Project->Properties->Add library-> select "User library" and press Next->User libraries->New
insert a new name and later us "Add Jar" that adds any jar you need to you library definition.
Later use this library in your project.
Sometimes adding jars directly in the blackberry project might cause some build problems. Here 's a solution that works (90%):
You have your blackberry project. Now create a new simple Java Project.
Right-click on it > Properties > Java Build Path and choose Libraries tab and click on Add External Jars to add the 3 jars that are in your system and you want to use. Then OK.
Now go back to your blackberry project and Right-click on it > Properties > Java Build Path and click on the Projects tab, click on Add and select the project you just created and OK.
Now go back and build your Blackberry project.
I hope this help.
If you add the JAR within the Eclipse workspace, say /myproject/WebRoot/WEB-INF/lib but Eclipse does not display the /lib when using the Select Jar pop-up, exit the wizard and refresh WebRoot (rtClick and take Refresh or F5): Eclipse only shows new libraries not already added to the project and usually needs a manual refresh first.

External jars in eclipse plug-in

I'm creating an eclipse plug-in and I'm having trouble with external jars. In my plug-in I start an application which requires some external jars. What do I have to do to export them automatically with the rest of the plug-in?
Thanks in advance :)
Open your plugin.xml
Go to Runtime tab and add your JAR in the classpath section
By following the steps below, the external JARs will be included when you export your plug-in:
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
Open the build.properties in your plug-in project and check the JARs you want to include in the build in the Binary Build section on the left.
This is an easy way, though it does create an additional plug-in.
In Eclipse:
Choose New>Other, then Plug-in Development>Plug-in from existing JAR archives.
Choose the jars you want to include.
On the next page, configure the plug-in.
In your plug-in's manifest, add the new plug-in as a dependency.
In your plug-in's Properties, add the new project under Java Build Path on the Projects tab.
Edit: You may be able to combine the jars into your plug-in by instead combining both suggestions of Zsolt and user714965 below.
This is what has worked for me. If they are truly external, and this is a project for your company that is not going to be in the "wild" and you control the environment, and you have them out on the file system say at /opt/java/lib/somedir/some.jar you can tell the bundle where to find them by adding them to the Bundle-ClassPath entry in the MANIFEST.MF under META-INF. The syntax is:
Bundle-ClassPath: .,
external:/opt/java/lib/somedir/some.jar,
external:/opt/java/lib/someotherdir/someother.jar
Also it would be prudent to use these in your build path so that you are working with the same jars in both build and runtime environments.
I have done this where the Jars are multi-purpose (such as apache-commons) on our file systems and again we control the environment.
Reference the following:
http://www.eclipsezone.com/eclipse/forums/t51870.html
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
..but as apposed to Zsolt Török (his solution did not work for me) I double-clicked on the plugin.xml, went to the build tab, at the bottom, I clicked Add JARs..., and hey presto, it showed my project, and I then navigated to lib and included the external jar, as per step 1.
The approach from Andy Thomas mostly works, but you also need to export the packages needed by the existing plugin in the new wrapper plugin so that they can be accessed by the plugin at runtime.

i could not find org.codehaus.staxmate.dom package

I use netbeans 6.9 I want to use org.codehaus.staxmate.dom package but in does not exist. How can I add this package?
Download the jar files from http://staxmate.codehaus.org/
Open up Netbeans and add the jars that you fetched from 1
to add the jars, open up Tools -> Libraries and create a new class library. Finally, add this library to the project's "compile" tab under its libraries section
alternately you can simply right click the project -> properties and then add the jars under the "compile" tab under libraries
Generally, make it point to look for the jar file names here : http://www.jarfinder.com/
That will help you decide the jar file needed and where to download it from as well :)
Download staxmate from:
The Staxmate Web Site.
This package is not included in standard Java Runtime Environment. So,
you either have to download corresponding jar manually, and specify as library in your project configuration
or have to use some build manager in your project (for example, Maven) and specify dependency on corresponding package

Categories

Resources