tags:

views:

43

answers:

3

Hey

A newbie to Eclipse and Java...can anyone tell me how could I install the Apache common lang 2.5 in Eclipse?

http://commons.apache.org/lang/download_lang.cgi

Thanks!

+1  A: 

You could create a User Library using Apache Commons Lang in Eclipse. User library is a set of jars (these jars can be stored wherever you like). Once defined, user library can be reused in various projects.

You can find more information how to do this for example here (in an accepted answer).

After creating a user library you can add it to your projects just as any other library (Project Properties -> Java Build Path -> Libraries -> Add library -> User library -> Next -> choose your library).

Piotr
Thanks Piotr, that works.
tom
Unfortunally getting the following exception when trying to use the StringEscapeUtils class. Any reason why? java.lang.ClassNotFoundException: org.apache.commons.lang.StringEscapeUtils at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:151) at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
tom
this probably happens when you run the application ? The library is most likely not added to the classpath of the application, see my answer below for a 'how to do that'
Redlab
I can see in the stack trace that you are using Google App Engine. I haven't used it but I suppose the problem is related to it. You should probably find some info on how too use additional jars in Google App Engine.
Piotr
You can also try this, but again as I am not familiar with GAE this is guessing:). When you use user libs the actual jars from Commons Lang are probably outside your project dir and maybe that is the problem (perhaps GAE requires them to be in your project). You can try to add jars differently:(1) copy Apache Commons Lang jars to `WEB-INF/lib` in your project, (2) right click on these jars and click `Build Path` and `Add to build path`.This is another way of adding libs (you can use it instead of user libs). However by doing this you have to copy jars to every project you want to use them in.
Piotr
Here there was a similar problem with GAE (stack trace is very similar): http://stackoverflow.com/questions/2205648/cannot-use-external-libraries-for-google-app-engine-java-project. You may take a look at the answer. And here: http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine you can find what Java libs are supported by GAE.
Piotr
Also take a look at http://stackoverflow.com/questions/3098783/does-eclipse-upload-3rd-party-gwt-libraries-to-gae
Piotr
+1  A: 

Detailed steps -

0) Download commons-lang-2.5-bin.zip from Apache Commons - Lang Downloads http://commons.apache.org/lang/download_lang.cgi Expand the archive in a directory (eg. \projects\commons-lang-2.5)

In Eclipse -

1). Put the library in the Java build path

Eclipse -> Preferences: Java - Build path - User Libraries push the "New..." button, and in the "User library name:" enter 'appache-commons-lang'.

Click to select "appache-commons-lang" in the "Defined user libraries" list and then click on the "Add JARs..." button and browse for commons-lang-2.5.jar (in the folder saved earlier) and select it.

In the "Defined user libraries", under commons-lang-2.5.jar need to have "Source attachment" and "Javadoc location" specified. For each of them, select it, then push "Edit..." , then "External file" and browse for the corresponding jar (commons-lang-2.5-sources.jar and commons-lang-2.5-javadoc.jar)

2) In the project add this user library In the Package Explorer right-click on the project name, go to Properties, and select the Libraries tab; click the "Add Library..." button, from the list select "User library" , "Next", mark [x] appache-commons-lang, and click "Finish"

tom
+1  A: 

You could also do it on a per project basis

Right click your project -> buildpath -> configure buildpath -> add libraries -> add jar -> select the jar you want to add as dependency to your project

(or use maven which does it all for you on creating the eclipse project)

Redlab