2

I am trying to use a feature from the Apache Commons called StringUtils. However this requires you download the libary and add it so I can use the code import org.apache.commons.lang3.StringUtils;. My problem is I am unsure of where to add it to so that I may compile my program in command prompt. I am also unaware of what file I should to add into the required folder.

Any help would be greatly appreciated.

Dan
  • 7,286
  • 6
  • 49
  • 114
  • I am not using any IDE or any other programs. I am only using [Notepad++](http://notepad-plus-plus.org/) to try and write my code – Dan May 05 '15 at 20:17
  • 1
    http://docs.oracle.com/javase/tutorial/essential/environment/paths.html – ControlAltDel May 05 '15 at 20:20

3 Answers3

5

You'll have to make sure that the library (usually a JAR file) is in the classpath when you compile and run your application that uses the library.

The classpath is the set of JAR files and directories that Java uses to find Java class files.

See PATH and CLASSPATH in Oracle's Java Tutorials. (This is about setting the environment variables PATH and CLASSPATH).

As an alternative to setting the CLASSPATH environment variable, you can use the -cp or -classpath options of the javac and java commands:

javac -cp C:\MyProject\lib\somelibrary.jar;. com\mypackage\MyProgram.java

java -cp C:\MyProject\lib\somelibrary.jar;. com.mypackage.MyProgram
Jesper
  • 202,709
  • 46
  • 318
  • 350
1

If you are not using any IDE, then include below line in your .java file.

import org.apache.commons.lang3.StringUtils;

then we you compile the .java class from cmd prompt, include the apache commons jar in classpath. like

javac -cp ../commons**.jar your_class.java
K139
  • 3,654
  • 13
  • 17
0

You will need the CLASSPATH environment variable to point to it. Link.

Given the context of the question I assume you are not using maven or an IDE. If you are there are simpler ways.

Captain Man
  • 6,997
  • 6
  • 48
  • 74