Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

classpath - What exactly is a class path in java?

I wrote a program that works on my laptop perfectly, but I really want it to work on a server that I have. Using NetBeans, I've clean and built the project. I copied the contents of the folder dist on my server but I cannot seem to get to work by using command

java -jar nameOfFile.jar

I get the error

java.lang.NoClassDefFoundError: org/....

I have been doing some reading and from what I gather is that I need to pretty much specify where the libraries that I've used are located. Well they are located in a subfolder called lib.

Question:

So what would I need to do in order to be able to run my jar?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

CLASSPATH is an environment variable that helps us to educate the Java Virtual Machine from where it will start searching for .class files.

We should store the root of the package hierarchies in the CLASSPATH environment variables.

In case of adding or using jar libraries in our project, we should put the location of the jar file in the CLASSPATH environment variable.

Example: If we are using jdbc mysql jar file in our java project, We have to update the location of the mysql jar file in the CLASSPATH environment variable. if our mysql.jar is in c:drivermysql.jar then

We can set the classpath through DOS in Windows

set CLASSPATH=%CLASSPATH%;c:drivermysql.jar 

In Linux we can do

export CLASSPATH=$CLASSPATH:[path of the jar]

Hope it helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...