How to get Netbeans 6.5 shareable libraries working - java

I created a Web application in Netbeans 6.5. Now I want to use the Joda Time library. I want to share this library via subversion, because I don't want my team mates to be dependend on some Netbeans configuration.
Just to get the project working, I first added the library to the Netbeans library (Tools->Library). This worked OK. The JAR is added to the classpath, and is also deployed.
But when I create a shared library (via Project Properties->Libraries->Browse/New Libraries Folder), the JAR is not in the classpath. I get the error message package org.joda.time does not exist on the code import org.joda.time.*.
Any ideas?

What is the scope of this library? Is this library used for just this particular web-application?
If so, can we put the library in the WEB-INF/lib directory and check that into subversion as well?
Libraries in the WEB-INF/lib directory should be automatically added to the classpath of the project.

Here is what I did:
Tools -> Library -> New Library...
called the library joda-time
add added the joda-time-1.6.jar file to it
Project -> Properties -> Libraries
under the compile tab
Add library...
selected joda-time
(Edit, think I see the issue now - but perhaps not).
You need to add the library to the compile libraries AND add it to the distribution libraries. Or am I misunderstanding the question?

when creating a 'new project', there is an option to enable 'dedicated folder for libraries'. That way, the libraries will also be committed to the repository and your peer developer can checkout your project with all the libraries, your project has dependencies upon, thereby eliminating netbeans configuration bound.

In scenario where a project depends on JARs which can be placed in different locations for different users, a named IDE variable can be used.
http://wiki.netbeans.org/NewAndNoteWorthyNB65#section-NewAndNoteWorthyNB65-VariableBasedPathsInJ2SEJ2EEProjects
Another option would be to use the Maven plugin which already works quite well in NetBeans 6.5. A Intranet repository for the Artifact Jar files could be placed on a file server, or managed through a Maven Proxy like Nexus.

This blog entry describes a hack that worked in NetBeans 5. I don't know if it will work in NetBeans 6.5. I also don't know if this will work if you are building files nightly on a server.
http://blogs.oracle.com/gjmurphy/entry/using_netbeans_free-form_projects_as
I remember setting up shared libraries like this 8 years ago in JBuilder. I wish Netbeans had it by now.

Related

Where to put Java libraries?

I'd like to know how I can add Java libraries to an Eclipse project on a development machine so that they can be added to an Eclipse project without causing errors when someone who has the library in a different location. For example, one developer might add an external JAR in C:\Java, but another might have the same JAR somewhere else. (Where's C:\Java on Mac OS?) I thought I might set the CLASSPATH environment variable, but I can't figure how to add an external JAR from the CLASSPATH environment variable. I'd like to do this so that it works with any workspace. Is this possible?
This is specifically for use with Anypoint Studio, but I think the same problem would exist with any Eclipse-based IDE.
In general, it's recommended to either embed JARs directly into the project, usually in a /lib folder of the project, as described here; or to use a tool like Gradle or Maven to manage dependencies, both of which have nice plugins to support their use in Eclipse.
Another alternative would be to use a Classpath Variable to refer to the JAR(s), which abstracts the physical location so that it can be set on a per-workspace basis.
I think the best way to add library to eclipse project is creating a directory - lib in your project directory. Then add the whole lib to you eclipse class path. You can follow these step to add a lib to class path -
Right click on project and select properties
Select Java Build Path
click Add Library and create User Library
Now add External Jars to this library create at step 3.
By this a .classpath file is crated in you project directory and the CLASSPATH problem will be resolved
I guess the best way to do that would be using Maven, or a similar build system that can construct your Classpath base on dependencies.
You can add the dependencies to your pom and having the jars in your local maven repository in the machine.
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Because in any other approach you will need to maintain everything manually, and when having different OS the path will change.
Eclipse is just the IDE that will help to write code and assemble the project (JAR, WAR, ... ). You can add your external jars from wherever you want, and when you want to export your project (with eclipse) you may choose to package the required libraries into the jar.
However, I recommend always to use maven (or something like ) to avoid this kind of problems.
Part1:(import .jar file as library in Eclipse)
You make a new project to Eclipse(name:Project1)
When you open it you see JRE System Library[java version something]
1.right click on JRE System Library
2.Go->Build Path->Configure Build Path
3.You can see (Up right Corner the button[add jars or add external jars]
*Here i advise you to choose the first(add jars) but..
*First copy(or move) the (name).jar inside the project((example):Project 1)
*Now you can add it with the button(add jars).
*In this way when you finish your project the (name).jar will be
imported inside the project(If you export it as a .jar from Eclipse)
..Now you can call any method of (name).jar just(import it into the class
you want to use and call it)

how to share user libraries across multiple systems without exporting and importing

I am a newbie, Please bear if i am silly. I have created a java project in eclipse which uses includes multiple jars like Apache Commons DBCP, dbutils, commons pool and some mysql jdbc driver. Instead of adding these jar directly to the project, i want to create different user libraries one for each and add the respective jars and its source and its javadoc into it.
So i created the user libraries and added the respective things in it and added those user libraries into project. Everything is fine upto that. But I want to work with same project in my home machine and when i imported that into eclipse in my home machine, those user libraries are empty. I undestood eclipse stores those info in the workspace and in my new workspace i am not able to use that libraries.
So i tried creating a new folder "lib" in the project and added all those jar into that folder which will always go with the project and when i creating the user libraries, this time while adding the jars i selected the option add jar-> workspace->lib->... and added those jar into the user library assuming that the lib folder is within the project and so the user libraries stay accros the workspaace but i failed again. Its working out. So how can use the libraries in different workspaces without importing and exporting... Please help me...
I do know ${project_loc} will give the project location. So is there anything i can say ${project_loc}/lib/commons-dbcp.jar to the user libraries.
I think you are viewing Package Explore
Open the Project Explorer instead.
I'd rather suggest to look at Apache Maven, which does allow you to configure dependencies for your project and build it (almost) everywhere.
It also has some plugins for integrate with Eclipse, so you can share your project easily without copying libraries manually.

Required Java libraries in Eclipse when working on multiple OSs

I'm developing an AppEngine project in Java.
I'm working on a MacBook and on other two PCs.
I'm using a hosted SVN as my RC.
I included some libraries from the GAE plugin in my project:
gwt-dev.jar, gwt-user.jar', validation-api-1.0.0.GA.jar.
I did that in the Java Build Path in the project properties.
Every time I switch a computer, I get an error:
Project '' is missing required library: ''. Off course, the path is changing between computers.
How can I resolve this issue?
Should I remove this settings from being stored on the SVN repository? If I shpould, how can I do that?
You should not persist any user-specific path information. Set your projects up by hand and then check out the user-agnostic stuff.
We have the same problem with IntelliJ. The answer is to check in only user-agnostic information, or get an IDE that's smart enough to use relative paths.
If you add 3rd party libraries to the project, make sure they are copied into your /lib directory and not in a path that's unique to you.
Create a project for the libraries.
Put the libraries in the project.
Export the jar files.
Set this newly created project as a dependency in the main project.

How to add source files of library jars?

I am using Eclipse IDE and its derivative like Spring IDE for Java development.
In a web application project, I add external jars like Spring MVC jars, Apache commons jars etc to the Web App library folder, hence they are automatically added to the build path. There are many jars in the Web App library folder.
I want to create folder in the project and add all the source files (zip/jar) of the libraries included in Web App library folder, so that I can navigate through the source of libraries from the Java editor window. Whenever I add a source zip/jar file to this folder, Eclipse should detect it and use it whenever I want to navigate to the source of a library.
Is the above possible in eclipse?
Note: I know how to add source files
for each individual jar by navigating
to the build path window and
specifying the source location. But
this is very crude way, and I need to
do for every library individually.
Also the drawback is that source path
is absolute, which means if I import
the project into another computer then
I need to create the source path or
even worse I might have to add the
source files individually again.
One way to automagically get the sources for the jars would be some kind of dependency management system. Most people would scream Maven (2/3) by now, but others exist and work well. Maven does have nice Eclipse integration, so that should be a plus.
The downside is that setting up a Maven project just for it's dependency management can seem overkill. Another point is that all the jars you depend on should be "Mavenized" as well.
As far as I know Eclipse wont automatically detect/scan source archive files and link them up to libraries in your workspace in the way you described it.
I agree with #Gressie on using Maven and the Eclipse Maven plugins -- as in that case it's just a matter of ticking a few boxes and Maven will do that for you.
If however your project is not Maven-ized, you can still do this in Eclipse but it's more tedious:
for each one of the jars in your project (which appear under the dependecies section) right click on it and select properties
in the dialog that pops up you have (at least) 2 locations you can configure: java source attachment -- simply browse to your jar with the sources -- and also javadoc location (point it to the jar with javadoc if you want the javadoc to appear as a tooltip when you hover the mouse over one of the classes/methods/etc in that library).

How do I make Eclipse automatically include jars I place in my WEB-INF/lib folder into my project?

When I was doing JSP/Servlet programming, whenever I dropped 3rd party libraries into the WEB-INF/lib folder, they were automatically included in the project classpath. In GWT, this is not the case. Anyone know why? I loved how easy this was in JSP and I'd like these jars to be included automatically the same way.
If you are using the Google Plugin for Eclipse then my understanding is that a Google Web Application Project is just not the same animal than a Dynamic Web Project and thus behave differently. So if your project depends on libraries not provided by the GWT and App Engine SDKs, you'll need to put them in war/WEB-INF/lib and to add them explicitly to your Java build path.
In Eclipse Galileo, right click the web project and select build path then select the Java EE Module Dependencies and add the jars.
There is a plug-in technique that may help you if you want a directory where new jars are automatically updated in your build path, see this other post:
Eclipse buildpath automatically taking all JARs of a internal directory
The reason it works like this for your JSP's is because that is how the Dynamic Web Project was made to behave.
"If you remove a library path entry but not the JAR file, the library entry will be re-added to the path automatically." from http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.wst.webtools.doc.user/topics/ccwebprj.html
You could adopt Maven and use the Maven Eclipse Plugin; this plugin would update your classpath whenever you add a dependency. There may be a similar plugin for Ivy.

Categories