47

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
prayagupa
  • 30,204
  • 14
  • 155
  • 192
gbegley
  • 2,609
  • 5
  • 29
  • 41

5 Answers5

50

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/

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
rado
  • 4,040
  • 3
  • 32
  • 26
  • Similarly, for tomcat there's webapp-runner: https://github.com/jsimone/webapp-runner – ryenus Aug 17 '15 at 15:19
  • Not sure why, but this gives `java.lang.NoClassDefFoundError: org/apache/tomcat/util/IntrospectionUtils` error. Is it related? – zygimantus Jul 05 '17 at 10:52
7

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

mckamey
  • 17,359
  • 16
  • 83
  • 116
4

Using jetty-runner-minimal:

$ git clone https://github.com/kissaten/jetty-runner-minimal
$ cd jetty-runner-minimal
$ mvn package

$ wget https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
$ java -jar target/dependency/jetty-runner.jar sample.war
tokland
  • 66,169
  • 13
  • 144
  • 170
4

install maven from command line:

sudo apt install maven

run war from command line on folder, where pom.xml:

mvn jetty:run-war
Peter Kofler
  • 9,252
  • 8
  • 51
  • 79
2

It's possible, if you have the appropriate start config (jetty.xml) set up.

Out of the box, jetty doesn't ship with a jetty.xml that does that, but you could write one easily enough.

That would mean you'd either

  1. Have a command line that was more like

    java -jar $jettyHome/start.jar -Dwar.location=myApp.war -DcontextPath=/myApp jetty-myapp.xml
    

    or

    java -jar $jettyHome/start.jar -Dwar.location=myApp.war -DcontextPath=/myApp etc/jetty.xml etc/jetty-plus.xml jetty-deploy-app.xml
    
  2. Override the etc/jetty.xml yourself and put the info you want in there.

Jetty startup is pretty straight forward, so it's really just about producing an XML file that does what you want. That XML file can read values from system properties, so you can use your various "-D" options.

Tim
  • 6,406
  • 22
  • 34
  • By "put the info you want in [ect/jetty.xml]" does this mean I could configure etc/jetty.xml with system properties passed in the command line, and then be able to run *any& war file on my box with a single command, or would the configuration be to a specific war? – gbegley Jan 21 '11 at 19:42
  • Yes, it should be possible to do that. I haven't actually done it, so there might be some obstacle I haven't considered, but Jetty's XML configuration format allows you to do pretty much anything you need, so I can't see a reason why it wouldn't work. If I get the time, I'll look at trying it myself. – Tim Jan 24 '11 at 05:38