简体   繁体   中英

run a java program

I want to run a java program using shell script. The java program is in p2 directory and its name is maxconnect4 and I have already compiled it, the class name is maxconnect4. I write the shell commands like this:

java p2/maxconnect4 arg1 arg2 arg3

This shell command does not work. It give an error: Exception in thread "main" java.lang.NoClassDefFoundError: p2/maxconnect

However, I compile the java program in this way:

javac p2/*.java, and it works.

Assuming that the class has package p2; declared, that should work -- although the more standard way is to use dots instead of slashes in the fully-qualified classname -- java p2.maxconnect .

If the class has no package declaration, try java -cp p2 maxconnect . You need to specify a classpath such that the class file is found at the top level.

If the class has some other package declaration, you need to put it into a folder that matches its package.

Try with

java p2.maxconnect4 arg1 arg2 arg3

Also, you can try to check the class name, and verify if the file p2/maxconnect4.class exists.

Just use java -cp p2 maxconnect4 arg1 arg2 arg3 . -cp sets the classpath of the JVM. Edit: I assume you don't use a package for maxconnect4.

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