Say you have multiple jar files a.jar,b.jar and c.jar. To add them to classpath while compiling you need to do

$javac -cp .:a.jar:b.jar:c.jar HelloWorld.java

To run do

$java -cp .:a.jar:b.jar:c.jar HelloWorld
Answer from noPE on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › jvm › ways to add jars to classpath in java
Ways to Add JARs to Classpath in Java | Baeldung
July 19, 2025 - It’s important to note that the ... option. Adding JARs in the lib/ext directory of the Java installation is a legacy mechanism, where JAR files placed in it are automatically added to the classpath....
🌐
Chilkat
chilkatsoft.com › java-classpath-Linux.asp
Java JAR Archives and classpath on Linux
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.
🌐
Wikitechy
wikitechy.com › tutorials › java › how-to-add-jar-file-to-classpath-in-java
How to add JAR file to Classpath in Java - By Microsoft Awarded MVP - Learn in 30sec | wikitechy
JAR from ext directory is loaded by extension Classloader and it has higher priority than application class loader which loads JAR from either CLASSPATH environment variable or directories specified in -classpath or -cp option. These were couple of ways you can add JAR files in your Classpath.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Include Jars In Java Classpath Example - Java Code Geeks
February 13, 2025 - Navigate to the Libraries tab and click Add External JARs.... Browse and select the required JAR file, then click Apply and Close. Once added, Eclipse automatically includes the JAR in the classpath for compilation and execution.
🌐
TutorialsPoint
tutorialspoint.com › how-to-add-jar-file-to-classpath-in-java
How to set classpath when class files are in .jar file using Java
July 21, 2023 - Following example demonstrates how to set class path when classes are stored in a .jar or .zip file. c:> java -classpath C:\java\myclasses.jar utility.testapp.main
Find elsewhere
🌐
YouTube
youtube.com › watch
Add JAR file to java program using javac -classpath in linux terminal - YouTube
This video is a quick tutorial on how to add a jar file, located in the same directory as your program, using javac classpath.
Published   August 16, 2015
🌐
How to do in Java
howtodoinjava.com › home › java basics › java classpath
How to set CLASSPATH in Java - HowToDoInJava
February 23, 2023 - However, the second statement “$ java –classpath C:\dependency\framework.jar MyApp” fails with error unable to find MyApp class and requires updating the classpath including the location of MyApp.class which is the current directory in this case. Reply · Thanks for the feedback. Updated the article. It requires to run the javac and java command from the same directory where the java file is placed. Reply · How to set the classpath through our java program dynamically? Reply · //Linux/Unix $ export CLASSPATH=/dependency/framework.jar:/location/otherFramework.jar $ export C:\dependency\framework.jar:C:\location\*.jar
🌐
Blogger
javarevisited.blogspot.com › 2012 › 10 › 5-ways-to-add-multiple-jar-to-classpath-java.html
5 ways to add multiple JAR in to Classpath in Java - Examples
August 31, 2021 - From Java 1.6+ onwards you can use a wildcard to include all jars in a directory into the set classpath or provide it to the Java program directly using -classpath command-line option.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › unix › classpath.html
2 Setting the Class Path
April 21, 2026 - When classes are stored in an archive file (a zip or JAR file) the class path entry is the path to and including the zip or JAR file. For example, the command to use a class library that is in a JAR file as follows: java -classpath /java/MyClasses/myclasses.jar utility.myapp.Cool
🌐
GitHub
gist.github.com › dmarcuse › 28b4fe1f27f2aae9e2c4bd0e4ccac56c
Add jars to the classpath at runtime! · GitHub
September 14, 2016 - Add jars to the classpath at runtime! GitHub Gist: instantly share code, notes, and snippets.
Top answer
1 of 2
1

Try this

java -classpath ./db2jcc_license_cu.jar:./db2jcc4.jar:. CreateCoffees

when you use -classpath it looses current directory from classpath so it needs . in classpath as well explicitly

2 of 2
0

How to include the jars of your project into your runnable jar:

I'll walk you through it step by step with Eclipse Version: 3.7.2 running on Ubuntu 12.10. I'll also show you how to make the build.xml so you can do the ant jar from command line and create your jar with other imported jars extracted into it.

Basically you ask Eclipse to construct the build.xml that imports your libraries into your jar for you.

  1. Fire up Eclipse and make a new Java project, make a new package 'mypackage', add your main class: Runner Put this code in there.

  2. Now include the mysql-connector-java-5.1.28-bin.jar from Oracle which enables us to write Java to connect to the MySQL database. Do this by right clicking the project -> properties -> java build path -> Add External Jar -> pick mysql-connector-java-5.1.28-bin.jar.

  3. Run the program within eclipse, it should run, and tell you that the username/password is invalid which means Eclipse is properly configured with the jar.

  4. In Eclipse go to File -> Export -> Java -> Runnable Jar File. You will see this dialog:

    Make sure to set up the 'save as ant script' checkbox. That is what makes it so you can use the commandline to do an ant jar later.

  5. Then go to the terminal and look at the ant script:

So you see, I ran the jar and it didn't error out because it found the included mysql-connector-java-5.1.28-bin.jar embedded inside Hello.jar.

Look inside Hello.jar: vi Hello.jar and you will see many references to com/mysql/jdbc/stuff.class

To do ant jar on the commandline to do all this automatically: Rename buildant.xml to build.xml, and change the target name from create_run_jar to jar.

Then, from within MyProject you type ant jar and boom. You've got your jar inside MyProject. And you can invoke it using java -jar Hello.jar and it all works.

🌐
Unix.com
unix.com › unix for advanced & expert users
how to set jar classpath in unix - UNIX for Advanced & Expert Users - Unix Linux Community
December 2, 2009 - while running one script am gettng below error ERROR (class path) : /sbcimp/run/pkgs/MsgTechJavaUtils/1.4/lib/MsgTechUtils.jar does not exist. means need to set the class path in env i guess can someone suggest how to set this in redhat 5.3 ?
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › adding-jars-to-classpath-4175574953
Adding jars to classpath
Hi folks, I'm looking to use a script to add multiple jar libraries to CLASSPATH for a java project. Easy for me with a bat in Windows but I can't