-1

I'm working on a basic Java project to make me more comfortable with the language (I've just started learning), and have come across a problem when trying to use a 3rd party library - I'm trying to use Apache's Lang library. I'm not using Eclipse to write my program, which I believe has a tool which makes it easy to use 3rd party libraries, so I'm not sure how I can use this library. When I try to use it, the 2 errors I receive are 'error: package org.apache.commons.lang3 does not exist', and 'error: cannot find symbol' on the line in which I call the StringUtils class (part of the Lang library). How can I use the library? (I am definitely a beginner in Java).

0

What you're going to need to learn about is the Java classpath. In order to use a third party JAR, it needs to be on the classpath when executing your code.

Here is an excellent StackOverflow post which explains how to accomplish this.

  • Thanks - I think that helped a lot. The only problem is, I now cannot run the project, as it gives me an 'Error: Could not find or load main class' error, 'Caused by: java.lang.ClassNotFoundException: MyProgram'. There is no compilation error, but just an error when I run the class. Any ideas? (The command I use to run the class is 'java -cp lib/commons-lang3-3.5.jar MyProgram') – JAUER Aug 13 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.