├── .gitignore ├── pom.xml ├── readme.adoc └── src └── main ├── docker └── assembly.xml ├── java └── org │ └── javaee7 │ └── sample │ ├── MyApplication.java │ ├── Person.java │ ├── PersonDatabase.java │ └── PersonResource.java └── webapp ├── WEB-INF └── beans.xml └── index.jsp /.gitignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | nb-*.xml 3 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | org.javaee7.sample 5 | javaee7-docker-maven 6 | 1.0-SNAPSHOT 7 | war 8 | javaee7-docker-maven 9 | 10 | 11 | 12 | javax 13 | javaee-api 14 | 7.0 15 | provided 16 | 17 | 18 | 19 | javaee7-docker-maven 20 | 21 | 22 | maven-compiler-plugin 23 | 3.1 24 | 25 | 1.7 26 | 1.7 27 | 28 | 29 | 30 | maven-war-plugin 31 | 2.3 32 | 33 | false 34 | 35 | 36 | 37 | org.wildfly.plugins 38 | wildfly-maven-plugin 39 | 1.0.2.Final 40 | 41 | 42 | 43 | 44 | 45 | docker 46 | 47 | 48 | 49 | io.fabric8 50 | docker-maven-plugin 51 | 0.14.2 52 | 53 | 54 | 55 | user 56 | arungupta/javaee7-docker-maven 57 | 58 | jboss/wildfly:9.0.0.Final 59 | 60 | assembly.xml 61 | /opt/jboss/wildfly/standalone/deployments/ 62 | jboss:jboss:jboss 63 | 64 | 65 | 8080 66 | 67 | 68 | 69 | 70 | 71 | 8080:8080 72 | 73 | 74 | WF 75 | none 76 | cyan 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | docker:build 85 | package 86 | 87 | build 88 | 89 | 90 | 91 | docker:start 92 | install 93 | 94 | start 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /readme.adoc: -------------------------------------------------------------------------------- 1 | # Run Java EE 7 Application as Docker Container using Maven 2 | 3 | This sample application shows how to package a Java EE 7 application 4 | as Docker image and run it within a container using 5 | https://github.com/rhuss/docker-maven-plugin[docker-maven-plugin]. 6 | 7 | . Create and configure a Docker Machine as explained at 8 | http://blog.arungupta.me/docker-machine-seutp-docker-host-techtip78/. 9 | . `mvn package -Pdocker` to create the Docker image 10 | . `mvn install -Pdocker` to run the Docker container 11 | . Access the application `curl http://:8080/javaee7-docker-maven/resources/persons` 12 | .. `HOST>` can be found as `docker-machine ip ` 13 | -------------------------------------------------------------------------------- /src/main/docker/assembly.xml: -------------------------------------------------------------------------------- 1 | 4 | javaee7-docker-maven 5 | 6 | 7 | 8 | org.javaee7.sample:javaee7-docker-maven 9 | 10 | . 11 | javaee7-docker-maven.war 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/org/javaee7/sample/MyApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaee7.sample; 2 | 3 | import javax.ws.rs.ApplicationPath; 4 | import javax.ws.rs.core.Application; 5 | 6 | /** 7 | * @author arungupta 8 | */ 9 | @ApplicationPath("/resources") 10 | public class MyApplication extends Application { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/javaee7/sample/Person.java: -------------------------------------------------------------------------------- 1 | package org.javaee7.sample; 2 | 3 | import javax.xml.bind.annotation.XmlRootElement; 4 | 5 | /** 6 | * @author arungupta 7 | */ 8 | @XmlRootElement 9 | public class Person { 10 | private String name; 11 | 12 | public Person() { 13 | } 14 | 15 | public Person(String name) { 16 | this.name = name; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return name; 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/org/javaee7/sample/PersonDatabase.java: -------------------------------------------------------------------------------- 1 | package org.javaee7.sample; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import javax.annotation.PostConstruct; 7 | import javax.inject.Singleton; 8 | import javax.ws.rs.NotFoundException; 9 | 10 | /** 11 | * @author arungupta 12 | */ 13 | @Singleton 14 | public class PersonDatabase { 15 | 16 | List persons; 17 | 18 | @PostConstruct 19 | public void init() { 20 | persons = Arrays.asList( 21 | new Person("Penny"), 22 | new Person("Leonard"), 23 | new Person("Sheldon"), 24 | new Person("Amy"), 25 | new Person("Howard"), 26 | new Person("Bernadette"), 27 | new Person("Raj"), 28 | new Person("Priya")); 29 | } 30 | 31 | public Person[] currentList() { 32 | return persons.toArray(new Person[0]); 33 | } 34 | 35 | public Person getPerson(int id) { 36 | if (id < persons.size()) { 37 | return persons.get(id); 38 | } 39 | 40 | throw new NotFoundException("Person with id \"" + id + "\" not found."); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/javaee7/sample/PersonResource.java: -------------------------------------------------------------------------------- 1 | package org.javaee7.sample; 2 | 3 | import javax.inject.Inject; 4 | import javax.ws.rs.GET; 5 | import javax.ws.rs.Path; 6 | import javax.ws.rs.PathParam; 7 | import javax.ws.rs.Produces; 8 | 9 | /** 10 | * @author arungupta 11 | */ 12 | @Path("persons") 13 | public class PersonResource { 14 | 15 | @Inject 16 | PersonDatabase database; 17 | 18 | @GET 19 | @Produces("application/xml") 20 | public Person[] get() { 21 | return database.currentList(); 22 | } 23 | 24 | @GET 25 | @Path("{id}") 26 | @Produces("application/xml") 27 | public Person get(@PathParam("id") int id) { 28 | return database.getPerson(id); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | Java EE 7 Docker Maven Sample 7 | 8 | 9 |

Java EE 7 Docker Maven Sample!

10 | 11 | GET all the persons. 12 | 13 | 14 | --------------------------------------------------------------------------------