export CLASSPATH=/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar

or, if you already have some classpath set

export CLASSPATH=$CLASSPATH:/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar

and, if also you want to include current directory

export CLASSPATH=$CLASSPATH:/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar:.
Answer from zed_0xff on Stack Overflow
🌐
Michigan State University
web.pa.msu.edu › reference › jdk-1.2.2-docs › tooldocs › solaris › classpath-linux.html
Setting the class path
The class path can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and ...
🌐
Blogger
javarevisited.blogspot.com › 2011 › 01 › how-classpath-work-in-java.html
How to Set Classpath for Java on Windows and Linux? Steps and Example
In fact, CLASSPATH is an environment variable that is used by Java Virtual Machine to locate user-defined classes. As I said In this tutorial we will see How to set up the classpath for java in windows and Linux, java -classpath example in different scenarios, and the use of java -classpath or java -cp.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › unix › classpath.html
2 Setting the Class Path
April 21, 2026 - The class path is the path that the Java Runtime Environment (JRE) searches for classes and other resource files. ... The class search path (class path) can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable.
🌐
HowToDoInJava
howtodoinjava.com › home › java examples › java – set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS.
🌐
HowTech
howtech.tv › home › how to set and check classpath in linux
How to Set and Check Classpath in Linux - HowTech
September 6, 2013 - Step#1: Access Classpath First ... classpath has been currently set in Linux. Step#2: Update Classpath To set the classpath, type the command export CLASSPATH=/root/java and enter....
Find elsewhere
🌐
Chilkat
chilkatsoft.com › java-classpath-Linux.asp
Java JAR Archives and classpath on Linux
Set the classpath at runtime. There are several possible ways of doing this: ... javac -classpath ".:/chilkatJava/chilkat.jar" Test.java java -classpath ".:/chilkatJava/chilkat.jar" Test ... javac -Djava.class.path=.:/chilkatJava/chilkat.jar Test.java java -Djava.class.path=.:/chilkatJava/chilkat.jar Test · IMPORTANT:On Windows systems, the semicolon character should be used for the path separator. However, on Linux systems, the colon character should be used.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
If the version is old or you get the error java: Command not found, then the path is not properly set. To set the path permanently, set the path in your startup file. For C shell (csh), edit the startup file (~/.cshrc): ... For ksh, the startup file is named by the environment variable, ENV.
🌐
Coderanch
coderanch.com › t › 466452 › java › set-classpath-java-Linux
How to set classpath for java in Linux (Beginning Java forum at Coderanch)
October 14, 2009 - On Ubuntu, the best way to install Sun JDK 6, which will automatically set up your path correctly, is entering the command: sudo apt-get install sun-java6-jdk ... try like this.... export CLASSPATH=/local/home/soft/bea81sp6/jdk142_11 hope would help Thanks, Samir
🌐
How to do in Java
howtodoinjava.com › home › java basics › java classpath
How to set CLASSPATH in Java - HowToDoInJava
February 23, 2023 - Java Classpath separators are OS specific. Windows – ; [Semicolon] Linux/Unix – : [Colon] When you have set the location of jar files that are always required during the application runtime, then it’s probably best to add them in the machine’s environment variable 'CLASSPATH'.
🌐
Delft Stack
delftstack.com › home › howto › java › java classpath
How to Set Classpath in Java | Delft Stack
February 2, 2024 - In Linux/Unix, we can use the export CLASSPATH command to set the classpath. Use the colon as a separator for multiple paths. ... We can use the -classpath or the -cp option to set the classpath when compiling and running the class files.
Top answer
1 of 3
13

First, in general, setting the env var CLASSPATH usually causes more problems than it solves -- since not all app's want/need the same classpath, & often break when undesired or even unneeded jars are included in the classpath. A java app should only include the minimum number of jars it requires, no more, no less.

When you have specific, individual apps that do require that the classpath be set, then usually the command-line option is preferred: java -cp path1:path2:.... Desktop icons can have their command altered to include these options, or shell scripts can be modified to include these options.

That being said (and since there are always exceptions to the rule), then depending on the version of java (this requres java 6 or later), you can specify that a whole directory of jars be added to the classpath by adding a "*" at the end of a directory; e.g, the following:

 /dir1/foo.jar:/dir2/dir3:/dir5/dir6/*:etc...

Means:

  • /dir1/foo.jar - (the single jar) will be added to the classpath;
  • /dir2/dir3 - all un-jar'd classes in this directory will be added to the classpath (must be in proper package structure; e.g, com.my.Foo.class must be in /dir2/dir3/com/my/Foo.class)
  • /dir5/dir6/* - all jars in this directory (i.e., /dir5/dir6/*.jar) will be added to the classpath. Note that this "*" isn't a wildcard (you can't use f*.jar or even *.jar); it's a special character indicating "add all jars"

In general, if you have to add a whole directory of jars to the application's classpath, the app was not bundled correctly. Rather, the app should have a manifest containing the list of jars it depends on. Or at the very least, only one jar should be added to your classpath, and that jar can have in its manifest the whole list of jars in some subdirectory.

2 of 3
4

if you want to set classpath permanently then 1) find out where java is installed.. you may use "whereis java" openjdk-7/6 is in /usr/lib/jvm/.....

2) we need to set up CLASSPATH in /etc/environment

  sudo gedit /etc/environment

3) add the following likes .. ( DONT LEAVE ANY SPACES WHILE TYPING)(customize according to your java version and installation) (this home path is for open jdk 7)

   JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"

   export JAVA_HOME

   CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib:/home/laptop/Desktop/a2"

   export CLASSPATH

separate directory by ":"

🌐
Coderanch
coderanch.com › t › 612449 › os › Java-CLASSPATH-linux
Java CLASSPATH on linux (GNU/Linux forum at Coderanch)
For User level . Edit the /etc/bashrc ( or the /etc/profile ) and export the java path at the top of the file as follows Save and close . Now the user for which you have set the variable needs to logout and log back in so that the bashrc file will re-execute for that session.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-set-classpath-in-java
How to Set Classpath in Java? - GeeksforGeeks
July 23, 2025 - Find out where you have installed Java, basically, it's in /usr/lib/jvm path. Set the CLASSPATH in /etc/environment using
🌐
Blogger
javarevisited.blogspot.com › 2011 › 01 › how-classpath-work-in-java.html
Javarevisited: How to Set Classpath for Java on Windows and Linux? Steps and Example
In fact, CLASSPATH is an environment variable that is used by Java Virtual Machine to locate user-defined classes. As I said In this tutorial we will see How to set up the classpath for java in windows and Linux, java -classpath example in different scenarios, and the use of java -classpath or java -cp.