Include all the jars in a directory within the Java classpath

0 votes

how can we include all the jar files within a directory in the same classpath?

My attempt:  java -classpath lib/*.jar:. my.pack.Code1 and it is not able to find class files that are certainly in those jars. Do we need to add each jar file to the classpath separately one by one?

May 23, 2018 in Java by sharth
• 3,370 points
15,074 views

2 answers to this question.

0 votes
Windows:
java -cp ppp.jar;dir/* my.app.ClassName

Linux:
java -cp ppp.jar:dir/* my.app.ClassName

Note: 
Windows path separator is ";"
Linux path separator is ":"

In Windows if cp argument does not contains white space, the "quotes" is optional

Hope it helps!

To know more about Java, It's recommended to join our Java Training in Chennai today.

answered May 23, 2018 by Parth
• 4,640 points

edited Oct 7, 2021 by Sarfaraz
0 votes
Just use lib/*   not lib/*.jar  

That's the syntax 'java' uses.
answered Apr 6, 2019 by anonymous

Related Questions In Java

0 votes
2 answers

Get all the permutations of a string in Java

You could use recursion to do this.  Try ...READ MORE

answered Aug 21, 2019 in Java by Sirajul
• 59,230 points
2,187 views
+2 votes
3 answers

Listing all the subclasses of a specific class in Java

Try with BurningWave core library. Here an ...READ MORE

answered Dec 29, 2019 in Java by anonymous
• 460 points

edited Jan 9, 2020 by anonymous 14,151 views
0 votes
2 answers

What's the best way to check if a String represents an integer in Java?

You can also use regular expression. str.matches("-?\\d+"); It will ...READ MORE

answered Aug 9, 2018 in Java by Daisy
• 8,140 points
3,900 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,920 points
1,856 views
0 votes
1 answer

Retrieving the path of a running jar file

Its quite simple. Try using the below ...READ MORE

answered May 25, 2018 in Java by geek.erkami
• 2,680 points
10,648 views
0 votes
1 answer

How to run the JAR files in windows?

Following are the steps to run the ...READ MORE

answered May 28, 2018 in Java by Parth
• 4,640 points
1,097 views
0 votes
1 answer

How to run a JAR file in Java?

The command given below will help you ...READ MORE

answered Jun 1, 2018 in Java by Parth
• 4,640 points
7,362 views
+3 votes
13 answers

Unable to execute jar- file: “no main manifest attribute”

add a jar/manifest/attributes setting like this: apply plugin: ...READ MORE

answered Nov 27, 2018 in Java by krishti
216,093 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 28, 2018 in Java by samarth295
• 2,220 points
2,409 views
0 votes
2 answers

How to find out current working directory in Java?

You can also use java.nio.file.Path and java.nio.file.Paths. Path ...READ MORE

answered Jul 31, 2018 in Java by Sushmita
• 6,920 points
961 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP