Jetty Run War Using only command line

前端 未结 5 593
梦谈多话
梦谈多话 2020-12-22 23:48

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

Something like :

         


        
相关标签:
5条回答
  • 2020-12-23 00:19

    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

    0 讨论(0)
  • 2020-12-23 00:27

    install maven from command line:

    sudo apt install maven
    

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

    mvn jett:run-war
    
    0 讨论(0)
  • 2020-12-23 00:28

    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
    
    0 讨论(0)
  • 2020-12-23 00:29

    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/

    0 讨论(0)
  • 2020-12-23 00:34

    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.

    0 讨论(0)
提交回复
热议问题