Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run java class file inside the war file [duplicate]

Tags:

java

war

i am having war file called Sample.war. in this war file i have the main class called "Maintest" .i want to run or execute the Maintest class from out side the war .how to do this

like image 609
ssbecse Avatar asked May 22 '11 12:05

ssbecse


People also ask

How do I run a Java class in a WAR file?

Unlike executable jar there won't be executable war file and why to run class inside war file. Classes inside war files are directly/indirectly loaded by web container/server. if really want to run a class inside a jar which is inside war file, then putting the jar in classpath it can be run as usual.


1 Answers

War files are just Jar files with extra metadata. So, you should be fine to do:

java -classpath application.war Maintest

That will load the class Maintest from the war file application.war and run it

like image 107
Gagravarr Avatar answered Oct 09 '22 23:10

Gagravarr