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 22, 2018 in Java by sharth
• 3,350 points
3,281 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

answered May 22, 2018 by parth295
• 4,640 points
0 votes
Just use lib/*   not lib/*.jar  

That's the syntax 'java' uses.
answered Apr 6 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 in Java by Sirajul
• 40,990 points
124 views
0 votes
2 answers

Listing all the subclasses of a specific class in Java

This is not possible to do using ...READ MORE

answered Aug 21 in Java by Sirajul
• 40,990 points
448 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,050 points
267 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,880 points
629 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,640 points
1,542 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 parth295
• 4,640 points
112 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 parth295
• 4,640 points
1,335 views
+2 votes
10 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
31,784 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 27, 2018 in Java by samarth295
• 2,190 points
129 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 30, 2018 in Java by Sushmita
• 6,880 points
49 views