Jetty Run War Using only command line

2019-01-21 03:34发布

问题:

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

回答1:

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/



回答2:

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



回答3:

Using jetty-runner-minimal:

$ git clone https://github.com/kissaten/jetty-runner-minimal
$ cd jetty-runner-minimal && mvn package
$ java -jar jetty-runner-minimal/target/dependency/jetty-runner.jar myapp.war


回答4:

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.



回答5:

install maven from command line:

sudo apt install maven

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

mvn jett:run-war


标签: Jetty war