Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Java Class from a Jar thru a command line

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?

like image 489
Eugene Ramirez Avatar asked Feb 11 '26 16:02

Eugene Ramirez


1 Answers

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
like image 149
jitter Avatar answered Feb 14 '26 04:02

jitter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!