Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty Run War Using only command line

Tags:

war

jetty

Is it possible to use only the command line to Run jetty with only a specified war file and Context Path.

Something like :

java -jar $jettyHome/start.jar -Dwar.location=myApp.war -DcontextPath=/myApp OPTIONS=default,plus,jsp 
like image 535
gbegley Avatar asked Sep 02 '10 02:09

gbegley


People also ask

Can I run a war file from command line?

The Jenkins Web application ARchive (WAR) file can be started from the command line like this: Download the latest stable Jenkins WAR file to an appropriate directory on your machine. Open up a terminal/command prompt window to the download directory. Run the command java -jar jenkins.

How do I run a WAR file on a jetty server?

The easiest way to deploy a web application to Jetty server is probably by copying the WAR file into the $JETTY_HOME/webapps directory. Jetty will scan its $JETTY_HOME/webapps directory at startup for web applications to deploy. Our new app will be deployed at /jetty-app context.

How do I run a jar on a jetty server?

Standalone Startup The easiest way to start Jetty, is to use the start. jar that comes with the distribution. The default options may be specified in the start. ini file, or if that is not present, they are defined in the start.

How do you run a Jetty?

To start Jetty, switch on the command line to the installation directory and issue the following command. To stop Jetty press Ctrl + C . To start Jetty as Windows service you can use Apache Procrun.


2 Answers

Use the jetty runner.

 java -jar jetty-runner.jar my.war 

With Maven, you can install by adding to your pom.xml:

<build>     ...     <plugins>         ...         <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-dependency-plugin</artifactId>             <version>2.3</version>             <executions>                 <execution>                     <phase>package</phase>                     <goals><goal>copy</goal></goals>                     <configuration>                         <artifactItems>                             <artifactItem>                                 <groupId>org.mortbay.jetty</groupId>                                 <artifactId>jetty-runner</artifactId>                                 <version>7.5.4.v20111024</version>                                 <destFileName>jetty-runner.jar</destFileName>                             </artifactItem>                         </artifactItems>                     </configuration>                 </execution>             </executions>         </plugin>     </plugins> </build> 

Run:

mvn package 

And use as:

java -jar target/dependency/jetty-runner.jar target/*.war 

http://www.eclipse.org/jetty/documentation/current/runner.html

http://central.maven.org/maven2/org/eclipse/jetty/jetty-runner/

like image 87
rado Avatar answered Sep 21 '22 18:09

rado


I've written a tiny command line app / Maven archetype which works like how I thought this all should have in the first place. The bootstrap app lets you launch your servlet container of choice (Jetty, Tomcat, GlassFish) by just passing it the path to the WAR and your port.

Using Maven, you can create and package your own instance of this simple app:

mvn archetype:generate \     -DarchetypeGroupId=org.duelengine \     -DarchetypeArtifactId=war-bootstrap-archetype \     -DarchetypeVersion=0.2.1 

Then you launch it like this:

java -jar bootstrap.jar -war myapp.war -p 8080 -c /myapp --jetty 

Here's the source for the utility and the archetype: https://bitbucket.org/mckamey/war-bootstrap

like image 35
mckamey Avatar answered Sep 18 '22 18:09

mckamey