How to include an external JAR in a directory within the Java classpath and run the Java class?

elvis :

I have a Java file that contains an external JAR and I want to run it. It is a simple project: https://github.com/eveningstar33/external-jar and I tested it with Java 8 and also with Java 11. The command to create the class file is javac -cp ./lib/* HelloWorld.java and it's working, but if I try to run the class using this command: java -cp ./lib/*:./ HelloWorld it doesn't work and I get this error message:

Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld

enter image description here

What should I do to run it? Thank you!

Arvind Kumar Avinash :

Use java -cp ./lib/* HelloWorld to run the class.

Update:

If the one given above doesn't work, please try with a "" i.e. use java -cp "./lib/*" HelloWorld to run the class.

Another update (tested):

Sorry for posting earlier solutions without testing them myself. Now, I have tested the following to be working:

java -cp .:lib/* HelloWorld

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Java/OpenJDK: How to add JAR to classpath

From Java

How to set classpath for current directory in Java?

From Java

How to add a jar to the boot classpath in java 9

From Java

Dockerfile fails on java class not found, how to specify classpath or jar to ./mvnw?

From Java

How to run java class file which is in different directory?

From Java

Convert java class to jar and use it as external library

From Java

How do you change the CLASSPATH within Java?

From Java

How to run Java program in terminal with external library JAR

From Java

include external jar when running java -jar

From Java

How can I compile and run a Java class in a different directory?

From Java

How to run a java class with a jar in the classpath?

From Java

how to add a java class to a folder within a jar file

From Java

How to use Maven classpath to run Java main class?

From Java

How to run external testcase(Class,junit) in java program?

From Java

How do i include external .jar in my gradle java project?

From Java

How to run a java task automatically from an external jar?

From Dev

Java Jar - classpath issue

From Dev

command to run latest java jar in a directory

From Dev

How to add class files and folders to a jar file from a directory in Java

From Dev

Run A Java Program That Calls On An External Jar

From Dev

Run in Java external .jar application like .exe

From Dev

How to run the main method of a Java class in a jar?

From Dev

Java classpath issue with external jars

From Dev

Java classpath losing Main Class when multiple jar

From Dev

run classpath in external folder war file command Spring java

From Dev

How to include external jar file on java gradle project without it getting deleted after every build?

From Dev

Java - Class exists twice (on classpath and on application jar). LinkageError: ClassCastException

From Dev

How to load a java class outside the classpath?

From Dev

Unable to run java files with external jar in Ubuntu

Related Related

  1. 1

    Java/OpenJDK: How to add JAR to classpath

  2. 2

    How to set classpath for current directory in Java?

  3. 3

    How to add a jar to the boot classpath in java 9

  4. 4

    Dockerfile fails on java class not found, how to specify classpath or jar to ./mvnw?

  5. 5

    How to run java class file which is in different directory?

  6. 6

    Convert java class to jar and use it as external library

  7. 7

    How do you change the CLASSPATH within Java?

  8. 8

    How to run Java program in terminal with external library JAR

  9. 9

    include external jar when running java -jar

  10. 10

    How can I compile and run a Java class in a different directory?

  11. 11

    How to run a java class with a jar in the classpath?

  12. 12

    how to add a java class to a folder within a jar file

  13. 13

    How to use Maven classpath to run Java main class?

  14. 14

    How to run external testcase(Class,junit) in java program?

  15. 15

    How do i include external .jar in my gradle java project?

  16. 16

    How to run a java task automatically from an external jar?

  17. 17

    Java Jar - classpath issue

  18. 18

    command to run latest java jar in a directory

  19. 19

    How to add class files and folders to a jar file from a directory in Java

  20. 20

    Run A Java Program That Calls On An External Jar

  21. 21

    Run in Java external .jar application like .exe

  22. 22

    How to run the main method of a Java class in a jar?

  23. 23

    Java classpath issue with external jars

  24. 24

    Java classpath losing Main Class when multiple jar

  25. 25

    run classpath in external folder war file command Spring java

  26. 26

    How to include external jar file on java gradle project without it getting deleted after every build?

  27. 27

    Java - Class exists twice (on classpath and on application jar). LinkageError: ClassCastException

  28. 28

    How to load a java class outside the classpath?

  29. 29

    Unable to run java files with external jar in Ubuntu

HotTag

Archive