I've been trying for 1 week to run a simple java program using third party jar, but I keep getting error. Just now I try this program as below
import org.apache.commons.lang3.*;
public class HelloWorld{
public static void main(String[] args){
String x = "abcd";
System.out.println(StringUtils.capitalize(x));
}
}
and when I try to compile and run, command prompt return error as below
c:\training\java\exercise>javac -cp ".;./org/apache/commons/lang3/commons-lang3-3.9.jar" HelloWorld.java
HelloWorld.java:5: error: cannot find symbol
System.out.println(StringUtils.capitalize(x));
I take this example from this sites as for reference https://www.programcreek.com/2014/01/compile-and-run-java-in-command-line-with-external-jars/
can anyone help me how to solve this? Thanks in advance enter image description here
There is an article about just that available here
I assume you're on Windows as the working folder has disk C:
so it should be Windows.
Bottom line it looks like you're mixing the notions of folder and jar. Make sure that the folder C:\\training\\java\\exercise
contains both HelloWorld.java
and commons-lang3-3.9.jar
Also make sure you're in the C:\\training\\java\\exercise
folder
Then compile like this:
javac -cp ".;./commons-lang3-3.9.jar" HelloWorld.java
Now this should create HelloWorld.class
file
Now Run the java process:
java -cp ".;./commons-lang3-3.9.jar" HelloWorld
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.