Skip to content

Latest commit

 

History

History
317 lines (295 loc) · 14.5 KB

build-and-run-the-quickstart-with-bootable-jar.adoc

File metadata and controls

317 lines (295 loc) · 14.5 KB

Building and running the quickstart application in a bootable JAR

You can package a {productName} server and an application inside a bootable JAR. You can then run the application on a {productName} bare-metal platform or on a {productName} Openshift platform.

On a {productName} bare-metal platform

You can use the Maven plug-in to build a {productName} bootable JAR, and then you can run the application on a {productName} bare-metal platform. The following example demonstrates a quickstart pom.xml file that contains a Maven profile named bootable-jar:

      <profile>
          <id>bootable-jar</id>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.wildfly.plugins</groupId>
                      <artifactId>wildfly-jar-maven-plugin</artifactId>
                      <configuration>
                          <feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#${version.server.bootable-jar}</feature-pack-location>
                          <layers>
                              <layer>jaxrs-server</layer>
                              <layer>microprofile-platform</layer>
                          </layers>
                          <plugin-options>
                              <jboss-fork-embedded>true</jboss-fork-embedded>
                          </plugin-options>
                      </configuration>
                      <executions>
                          <execution>
                              <goals>
                                  <goal>package</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
      </profile>
Procedure
  1. Build the quickstart bootable JAR with the following command:

    $ mvn clean package -Pbootable-jar
  2. Run the quickstart application contained in the bootable JAR:

    $ java -jar target/{artifactId}-bootable.jar
  3. You can now interact with the quickstart application.

Note

After the quickstart application is deployed, the bootable JAR includes the application in the root context. Therefore, any URLs related to the application should not have the /{artifactId} path segment after HOST:PORT.

On a {productName} OpenShift platform

You can use the Maven plug-in to build a {productName} bootable JAR, and then you can run the application on a {productName} OpenShift platform. The following example demonstrates a quickstart pom.xml file that contains a Maven profile named bootable-jar-openshift:

      <profile>
          <id>bootable-jar-openshift</id>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.wildfly.plugins</groupId>
                      <artifactId>wildfly-jar-maven-plugin</artifactId>
                      <configuration>
                          <feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#${version.server.bootable-jar}</feature-pack-location>
                          <layers>
                              <layer>jaxrs-server</layer>
                              <layer>microprofile-platform</layer>
                          </layers>
                          <plugin-options>
                              <jboss-fork-embedded>true</jboss-fork-embedded>
                          </plugin-options>
                          <cloud/>
                      </configuration>
                      <executions>
                          <execution>
                              <goals>
                                  <goal>package</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <groupId>org.eclipse.jkube</groupId>
                      <artifactId>openshift-maven-plugin</artifactId>
                      <executions>
                          <execution>
                              <goals>
                                  <goal>resource</goal>
                                  <goal>build</goal>
                              </goals>
                          </execution>
                      </executions>
                      <configuration>
                          <enricher>
                              <config>
                                  <jkube-service>
                                      <type>NodePort</type>
                                  </jkube-service>
                              </config>
                          </enricher>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      </profile>
Procedure
  1. Log in to your OpenShift instance using the oc login command.

  2. Create a new project for the quickstart bootable JAR on OpenShift. For example:

    $ oc new-project bootable-jar-project
  3. Build the quickstart bootable JAR by issuing the following command. This command also completes the following tasks: creates the OpenShift deployment, service and route; generates a docker image and pushes the docker image to OpenShift; and runs the application.

    $ mvn oc:deploy -Pbootable-jar-openshift
  4. Get the URL of the route.

    $ oc get route
  5. Access the application in your web browser by using a URL. The URL is the value of the HOST/PORT field that was provided by the oc get route command output. For example, the route of the URL for the quickstart used in this procedure is https://HOST_PORT_Value/.

Customizing OpenShift resources with resource fragments

With the Eclipse JKube Maven plug-in, you can customize the generated OpenShift resources, such as deployments, routes, and so on, with YAML file extracts located in the src/main/jkube directory.

The route.yml file, which is located in the src/main/jkube directory, is an example of a resource fragment. You can configure this resource fragment to change the Openshift application service route to use HTTPS:

spec:
  tls:
    insecureEdgeTerminationPolicy: Redirect
    termination: edge
  to:
    kind: Service
    name: {artifactId}

For more information about resource fragments, see the Eclipse JKube documentation.