From 8cdfccd8370f12af98387a2f84e0593ae34170e5 Mon Sep 17 00:00:00 2001 From: Panagiotis Roubatsis Date: Thu, 7 Mar 2019 10:06:11 -0500 Subject: [PATCH] Fix broken guide (#36) * Fix maven-ear-plugin module URIs * Move aggregating build section * Re-arrange flow of the guide * Fix filepaths * Make "start/" consistent with "start" * Add .gitkeep file for server config directory * Replace Test.java with .gitkeep * Re-arrange "mvn install" instructions * Add hotspots for "jar", "war", and "ear" * Make tags in README self-closing * Remove sentence Andrew mentioned it --- README.adoc | 142 +++++++++--------- finish/ear/pom.xml | 6 +- start/ear/src/main/liberty/config/.gitkeep | 0 .../openliberty/guides/multimodules/.gitkeep | 0 .../openliberty/guides/multimodules/Test.java | 55 ------- 5 files changed, 73 insertions(+), 130 deletions(-) create mode 100644 start/ear/src/main/liberty/config/.gitkeep create mode 100644 start/ear/src/test/java/it/io/openliberty/guides/multimodules/.gitkeep delete mode 100644 start/ear/src/test/java/it/io/openliberty/guides/multimodules/Test.java diff --git a/README.adoc b/README.adoc index 196eb22..e04a70e 100644 --- a/README.adoc +++ b/README.adoc @@ -35,9 +35,6 @@ You will learn how to establish a dependency between a web module and a Java lib You will build a unit converter application that converts heights from centimeters into feet and inches. Enter heights in centimeters from a web page, and the application processes the input with functions in the JAR file to return the corresponding height in Imperial units. -When the application is running, you can access the unit converter at the following location: http://localhost:9080/converter[http://localhost:9080/converter^] - - // ================================================================================================= // Getting Started @@ -52,9 +49,9 @@ Access partial implementation of the application from the `start` folder. This f 2. Assemble the entire application into an EAR file. -3. Test the multi-module application. +3. Aggregate the entire build. -4. Aggregate the entire build. +4. Test the multi-module application. // ================================================================================================= @@ -123,7 +120,7 @@ Set the [hotspot=7-11 file=0]`basic configuration` for the project and set the [ The [hotspot=16-21 file=0]`Java library module` and the [hotspot=22-27 file=0]`web module` were added as dependencies. Specify [hotspot=26 file=0]`war` for the web module. If you don’t specify the web module, Maven looks for a JAR file. -The definition and configuration of the [hotspot=38-58 file=0]`maven-ear-plugin` plug-in were added to create an EAR file. Define the [hotspot=44-48 file=0]`` and [hotspot=49-55 file=0]`` modules to be packaged into the EAR file. +The definition and configuration of the [hotspot=38-58 file=0]`maven-ear-plugin` plug-in were added to create an EAR file. Define the [hotspot=44-48 file=0]`` and [hotspot=49-55 file=0]`` modules to be packaged into the EAR file. To customize the context root of the application, set the appropriate contextRoot in the webModule. Otherwise, Maven automatically uses the WAR file `artifactId` ID as the context root for the application while generating the `application.xml` file. To download and start an Open Liberty server, use the [hotspot=61-90 file=0]`liberty-maven-plugin` plug-in for Maven. This configuration is provided, and the executions of the plug-in follow the typical phases of a Maven life cycle. @@ -141,21 +138,84 @@ server.xml include::finish/ear/src/main/liberty/config/server.xml[tags=**] ---- +// ================================================================================================= +// Aggregating the entire build +// ================================================================================================= + +== Aggregating the entire build + +Because you have multiple modules, aggregate the Maven projects to simplify the build process. + +Create a parent `pom.xml` file under the `start` directory to link all of the child modules together. A template is provided for you. + +[role="code_command hotspot", subs="quotes"] +---- +#Replace the start/POM file.# +`pom.xml` +---- +start/pom.xml +[source, xml, linenums, role='code_column'] +---- +include::finish/pom.xml[tags=**] +---- +Set the [hotspot=13-17 file=0]`basic configuration` for the project. Set `pom` as the [hotspot=17 file=0]`` element of the parent `pom.xml` file. Specify `io.openliberty.guides` as the [hotspot=14 file=0]`` ID, which the child `pom.xml` files will inherit. + +In the parent `pom.xml` file, list all of the [hotspot=19-23 file=0]`` that you want to aggregate for the application. + +Lastly, + +[role="code_command hotspot", subs="quotes"] +---- +#Update the `pom.xml` in the child module `jar`, `war` and `ear` projects.# +`jar/pom.xml` +`war/pom.xml` +`ear/pom.xml` +---- + +[role="edit_command_text"] +Add a [hotspot=1-5 file=1]`` section just above `basic configuration` to each of the `pom.xml` files in the child modules, +such as the [hotspot=9-13 file=2]`jar`, [hotspot=14-19 file=3]`war`, and [hotspot=13-17 file=4]`ear` projects. + +pom.xml +[source, xml, linenums, role='code_column'] +---- +include::finish/ear/pom.xml[tags=parent] +---- + +jar/pom.xml +[source, xml, linenums, role='code_column'] +---- +include::finish/jar/pom.xml[tags=**] +---- + +war/pom.xml +[source, xml, linenums, role='code_column'] +---- +include::finish/war/pom.xml[tags=**] +---- + +ear/pom.xml +[source, xml, linenums, role='code_column'] +---- +include::finish/ear/pom.xml[tags=**] +---- + // ================================================================================================= // Building the modules // ================================================================================================= == Building the modules -To build the three modules, run the following commands from the `jar` directory, `war` directory, and `ear` directory in that order. Start with the `jar` directory, proceed to the `war` directory, and end with the `ear` directory. +This command creates a JAR file in the `jar/target` directory, a WAR file in the `war/target` directory, and an EAR file in the `ear/target` directory, which contains the JAR and WAR files. + +By aggregating the build in the previous section, you can run `mvn install` once from the `start` directory and it will automatically build all your modules. Use the following command to build the entire application from the `start` directory: [role=command] ---- mvn install ---- -These commands create a JAR file in the `jar/target` directory, a WAR file in the `war/target` directory, and an EAR file in the `ear/target` directory, which contains the JAR and WAR files. - +Since the modules are independent, you can re-build them individually by running `mvn install` from the corresponding module directory. // ================================================================================================= // Starting the application @@ -191,7 +251,7 @@ To test the multi-module application, add integration tests to the EAR project. [role="code_command hotspot", subs="quotes"] ---- #Create the `Test` class.# -`start/ear/src/test/java/it/io/openliberty/guides/multimodules/Test.java` +`ear/src/test/java/it/io/openliberty/guides/multimodules/Test.java` ---- Test.java [source, Java, linenums, role='code_column'] @@ -230,68 +290,6 @@ Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 ---- - -// ================================================================================================= -// Aggregating the entire build -// ================================================================================================= - -== Aggregating the entire build - -Because you have multiple modules, aggregate the Maven projects to simplify the build process. - -Create a parent `pom.xml` file under the `start` directory to link all of the child modules together. A template is provided for you. - -[role="code_command hotspot", subs="quotes"] ----- -#Replace the start/POM file.# -`start/pom.xml` ----- -start/pom.xml -[source, xml, linenums, role='code_column'] ----- -include::finish/pom.xml[tags=**] ----- -Set the [hotspot=13-17 file=0]`basic configuration` for the project. Set `pom` as the [hotspot=17 file=0]`` element of the parent `pom.xml` file. Specify `io.openliberty.guides` as the [hotspot=14 file=0]`` ID, which the child `pom.xml` files will inherit. - -In the parent `pom.xml` file, list all of the [hotspot=19-23 file=0]`` that you want to aggregate for the application. - -Lastly, - -[role="code_command hotspot", subs="quotes"] ----- -#Update the `pom.xml` in the child module `jar`, `war` and `ear` projects.# -`jar/pom.xml` -`war/pom.xml` -`ear/pom.xml` ----- - -[role="edit_command_text"] -Add a [hotspot=1-5]`` section just above `basic configuration` to each of the `pom.xml` files in the child modules, -such as the `jar`, `war`, and `ear` projects. - -pom.xml -[source, xml, linenums, role='code_column'] ----- -include::finish/ear/pom.xml[tags=parent] ----- - - -// ================================================================================================= -// Building the application -// ================================================================================================= - -== Building the application - -Use the following command to build the entire application from the `start` directory: - -[role=command] ----- -mvn install ----- - -You no longer need to execute multiple `mvn install` commands from different directories. With a single command, you can build and test the whole application and all of the modules. - - // ================================================================================================= // Congratulations! You're done! // ================================================================================================= diff --git a/finish/ear/pom.xml b/finish/ear/pom.xml index 2ed95a2..dd22a60 100644 --- a/finish/ear/pom.xml +++ b/finish/ear/pom.xml @@ -56,12 +56,12 @@ io.openliberty.guides io.openliberty.guides.multimodules.jar - io.openliberty.guides.multimodules.jar-0.0.1-SNAPSHOT.jar + /io.openliberty.guides.multimodules.jar-0.0.1-SNAPSHOT.jar io.openliberty.guides io.openliberty.guides.multimodules.war - io.openliberty.guides.multimodules.war-0.0.1-SNAPSHOT.war + /io.openliberty.guides.multimodules.war-0.0.1-SNAPSHOT.war /converter @@ -157,4 +157,4 @@ - \ No newline at end of file + diff --git a/start/ear/src/main/liberty/config/.gitkeep b/start/ear/src/main/liberty/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/start/ear/src/test/java/it/io/openliberty/guides/multimodules/.gitkeep b/start/ear/src/test/java/it/io/openliberty/guides/multimodules/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/start/ear/src/test/java/it/io/openliberty/guides/multimodules/Test.java b/start/ear/src/test/java/it/io/openliberty/guides/multimodules/Test.java deleted file mode 100644 index 3dd7ee4..0000000 --- a/start/ear/src/test/java/it/io/openliberty/guides/multimodules/Test.java +++ /dev/null @@ -1,55 +0,0 @@ -// tag::comment[] -/******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial implementation - *******************************************************************************/ -// end::comment[] -package it.io.openliberty.guides.multimodules; - -import static org.junit.Assert.*; -import java.net.HttpURLConnection; -import java.net.URL; -import javax.net.ssl.HttpsURLConnection; - -import java.io.BufferedReader; -import java.io.InputStreamReader; - -public class Test { - String port = System.getProperty("liberty.test.port"); - String war = "converter"; - String urlBase = "http://localhost:" + port + "/" + war + "/"; - - // tag::testIndexPage[] - // TO-DO: ADD THE testIndexPage TEST SNIPPET HERE - // end::testIndexPage[] - - // tag::testHeightsPage[] - // TO-DO: ADD THE testHeightsPage TEST SNIPPET HERE - // end::testHeightsPage[] - - private HttpURLConnection testRequestHelper(String url, String method) throws Exception { - URL obj = new URL(url); - HttpURLConnection con = (HttpURLConnection) obj.openConnection(); - // optional default is GET - con.setRequestMethod(method); - return con; - } - - private String testBufferHelper(HttpURLConnection con) throws Exception { - BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuffer response = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - in.close(); - return response.toString(); - } - -}