I have a jar file with several classes which have static main methods. Can I execute them inside the jar from the command line? If not, can I execute them one by one?
+9
A:
Windows
java -classpath .;path/to/yourlib.jar your.package.path.ClassWithMain
Linux (I guess)
java -classpath .:path/to/yourlib.jar your.package.path.ClassWithMain
Or if you don't use packages just do (for Windows)
java -classpath .;path/to/yourlib.jar ClassWithMain
jitter
2009-11-21 01:38:53
+1 but java -cp path/to/yourlib.jar your.package.path.ClassWithMain should work too. The . is superfluous if the only classes are in the jar.
PSpeed
2009-11-21 04:13:07
Shouldn't (or couldn't) you use backslashes in the classpath in the Windows example?
Derek Mahar
2009-11-22 01:59:46
Java will happily use forward slashes under Windows so it is sometimes easier/cleaner to just do it that way on all platforms.
PSpeed
2009-11-22 05:38:45
A:
If you don't know which class has static main method,you can use some java IDE,for example IntelliJ IDEA,it can find the classes with main() method,and then you can run it within your project.
liya
2009-11-21 02:21:05