开发者

Running a Java Class from a Jar thru a command line

开发者 https://www.devze.com 2022-12-11 22:01 出处:网络
I have a jar file with several classes w开发者_运维百科hich have static main methods.Can I execute them inside the jar from the command line? If not, can I execute them one by one? Windows

I have a jar file with several classes w开发者_运维百科hich have static main methods. Can I execute them inside the jar from the command line? If not, can I execute them one by one?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消