简体   繁体   中英

How to run java program with multiple jars and multiple classes with cmd or terminal?

This is what I have tried so far to compile

javac -d bin -cp "lib/*" src/*.java

This seems to compile everything correctly, the problem is when I try running. This what I tried

cd bin
java -cp "lib/*" App <arguments>
java -cp "../lib/*" App <arguments>

or from root directory

java -cp "lib/*" bin/App

I have tried multiple suggestions that I found online but none of them work. The error that I always get is

ClassNotFoundException

can someone please help me run this?

You have to include the bin directory in your classpath.

If you are inside the bin directory then you can use ".":

java -cp ".:../lib/*" App <arguments>

In Linux/Unix the classpath separator is ":", but in Windows it is ";".

Or if you are in the parent directory (where bin and lib directories are):

java -cp "bin:lib/*" App <arguments>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM