Jetty Run War Using only command line

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 15:58:51
rado

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/

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

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.

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
Alisher Gulov

install maven from command line:

sudo apt install maven

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

mvn jett:run-war
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!