Git Product home page Git Product logo

devcenter-jetty-runner's Introduction

Deploy a Java Web Application that launches with Jetty Runner

Follow each step to build an app from scratch, or skip to the end get the source for this article. You can also use almost any existing Maven webapp project.

Prerequisites

  • Basic Java knowledge, including an installed version of the JVM and Maven.
  • Basic Git knowledge, including an installed version of Git.

What is Jetty and Jetty Runner?

Jetty is a lightweight Java application server that offers a flexible array of options for how it can be launched. One popular option is using embedded Jetty the way that the java quickstart does. Another good option is the Jetty Runner jar file. Each version of Jetty that is released includes a Jetty Runner jar. This jar can be run directly from the java command and can be passed a war file to load right on the command line. An example of this would be:

$ java -jar jetty-runner.jar application.war

Jetty Runner will then launch a Jetty instance with the given war deployed to it.

Create an application if you don't already have one

$ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
...
[INFO] Generating project in Interactive mode
Define value for property 'groupId': : com.example
Define value for property 'artifactId': : helloworld

(you can pick any groupId or artifactId). You now have a complete Java web app in the helloworld directory.

Configure Maven to download Jetty Runner

Although not necessary for using Jetty Runner it's a good idea to have your build tool download Jetty Runner for you since your application will need it to run. You could, of course, just download Jetty Runner and use it to launch your application without doing this. However having all of your dependencies defined in your build descriptor is important for application portability and repeatability of deployment. In this case we're using Maven so we'll use the dependency plugin to download the jar. Add the following plugin configuration to your pom.xml:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.4</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals><goal>copy</goal></goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-runner</artifactId>
                <version>9.4.9.v20180320</version>
                <destFileName>jetty-runner.jar</destFileName>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
       </executions>
    </plugin>
  </plugins>
</build>

Run your application

To build your application simply run:

$ mvn package

And then run your app using the java command:

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

That's it. Your application should start up on port 8080.

Deploy your application to Heroku

Create a Procfile

You declare how you want your application executed in Procfile in the project root. Create this file with a single line:

web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war

Deploy to Heroku

Commit your changes to Git:

$ git init
$ git add .
$ git commit -m "Ready to deploy"

Create the app:

$ heroku create
Creating high-lightning-129... done, stack is cedar-14
http://high-lightning-129.herokuapp.com/ | [email protected]:high-lightning-129.git
Git remote heroku added

Deploy your code:

$ git push heroku master
Counting objects: 227, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (117/117), done.
Writing objects: 100% (227/227), 101.06 KiB, done.
Total 227 (delta 99), reused 220 (delta 98)

-----> Heroku receiving push
-----> Java app detected
-----> Installing Maven 3.3.3..... done
-----> Executing: mvn -B -DskipTests=true clean install
       [INFO] Scanning for projects...
       [INFO]                                                                         
       [INFO] ------------------------------------------------------------------------
       [INFO] Building petclinic 0.1.0.BUILD-SNAPSHOT
       [INFO] ------------------------------------------------------------------------
       ...
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD SUCCESS
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time: 36.612s
       [INFO] Finished at: Tue Aug 30 04:03:02 UTC 2011
       [INFO] Final Memory: 19M/287M
       [INFO] ------------------------------------------------------------------------
-----> Discovering process types
       Procfile declares types -> web

-----> Compiled slug size is 62.7MB
-----> Launching... done, v5
       http://pure-window-800.herokuapp.com deployed to Heroku

Congratulations! Your web app should now be up and running on Heroku. Open it in your browser with:

$ heroku open

devcenter-jetty-runner's People

Contributors

jkutner avatar

Stargazers

Meng Ye avatar Erik Kaplun avatar Syed Abdullah avatar Mitchell Seaton avatar Henry avatar Bohdan Mart avatar Orest Ivasiv avatar ichigotake avatar Eugene Letenkov avatar Hilmiy avatar Mikkel Dan-Rognlie avatar Anand Narasimhan avatar

Watchers

Morten Bagai avatar Aaron Quint avatar  avatar Christopher Stolt avatar Edu Fernández avatar Erik Jones avatar DJCP avatar Jason Harrison avatar Jordan Wilberding avatar Harold Giménez avatar Mike Hagedorn avatar Ransom Briggs avatar Jawaad Mahmood avatar Koes Bong avatar Jeremy West avatar Josh Simmons avatar Casey Duncan avatar Scott Clasen avatar Xe Iaso avatar Yoshi Oikawa avatar Tim Schmelmer avatar Sean Jezewski avatar Tom Reznick avatar Brad Gyger avatar  avatar Jens Schutt avatar Mike Selender avatar James Cloos avatar Shiva avatar Simon Peck avatar Gabriel Enslein avatar Enrique Carlos Mogollan avatar kristigray avatar Emilio Daniel González avatar Drew Fradette avatar Ryan Huber avatar D. Keith Robinson avatar Aaron Rosen avatar Yang Yang avatar Travis Longoria avatar  avatar Vikram Rana avatar Hillary Sanders avatar Chris Montes avatar JJ avatar Tim Wade avatar  avatar caio avatar  avatar Alan Scott avatar Jillian Wilmarth avatar Corey Martin avatar Naga Sowjanya(Sowju) Sutherland avatar Martin Sommer avatar Raghu Katti avatar NT avatar Patti Sutton avatar Jack Ziesing avatar Bob Wise avatar  avatar Arif Gursel avatar Nahid Samsami avatar Matt Tannahill avatar Danielle Adams avatar Balan Subramanian avatar Peter Siegel avatar JorDanee Key avatar Lenora Porter avatar  avatar NikitaKothari avatar Raphael Theberge avatar William Gradin avatar Samast Varma avatar  avatar Len Sorstokke avatar Jim Wunderlich avatar Dmytro (Dima) Kabanov avatar Rakhi Borthakur avatar Alexandra Dalton avatar  avatar William "Chip" Vaughn avatar  avatar Stephanie Chan avatar  avatar Pamela Nance avatar Christian Samuel avatar  avatar Ike avatar Jesse Soyland avatar Ian Coldwater avatar jigna bhatt avatar  avatar Dhaval Thakkar avatar Jialee Chau avatar Analia Cartagena avatar Gary Clark avatar Cecilia Quintana avatar Tomohiro Mitani avatar  avatar Jack Hu avatar

devcenter-jetty-runner's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.