Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the multi-module Maven project from the Open Liberty guide for "Creating a multi-module application". #1114

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Multi-module Maven project for Jakarta EE Pages 3.1

This test application has been derived from the Open Liberty guide for "Creating a multi-module application" that is available [here](https://openliberty.io/guides/maven-multimodules.html).

This application has been included in the Liberty Tools for IntelliJ repository as a reference to assist with development of features for multi-module Maven projects and is also intended for use in automated testing of those features. While support for multi-module Maven projects is still under development, Liberty Tools for IntelliJ may not behave as intended when interacting with this project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<!-- tag::packaging[] -->
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-ear</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- tag::packagingType[] -->
<packaging>ear</packaging>
<!-- end::packagingType[] -->
<!-- end::packaging[] -->

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<!-- Liberty configuration -->
<liberty.var.http.port>9080</liberty.var.http.port>
<liberty.var.https.port>9443</liberty.var.https.port>
</properties>

<dependencies>
<!-- web and jar modules as dependencies -->
<!-- tag::dependencies[] -->
<!-- tag::dependency-jar[] -->
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<!-- end::dependency-jar[] -->
<!-- tag::dependency-war[] -->
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- tag::warType[] -->
<type>war</type>
<!-- end::warType[] -->
</dependency>
<!-- end::dependency-war[] -->
<!-- end::dependencies[] -->

<!-- For tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- tag::maven-ear-plugin[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<modules>
<!-- tag::jarModule[] -->
<jarModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<uri>/guide-maven-multimodules-jar-1.0-SNAPSHOT.jar</uri>
</jarModule>
<!-- end::jarModule[] -->
<!-- tag::webModule[] -->
<webModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<uri>/guide-maven-multimodules-war-1.0-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<!-- tag::contextRoot[] -->
<contextRoot>/converter</contextRoot>
<!-- end::contextRoot[] -->
</webModule>
<!-- end::webModule[] -->
</modules>
</configuration>
</plugin>
<!-- end::maven-ear-plugin[] -->

<!-- Since the package type is ear,
need to run testCompile to compile the tests -->
<!-- tag::maven-compiler-plugin[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>test-compile</phase>
<!-- tag::testCompile[] -->
<goals>
<goal>testCompile</goal>
</goals>
<!-- end::testCompile[] -->
</execution>
</executions>
</plugin>
<!-- end::maven-compiler-plugin[] -->

<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<systemPropertyVariables>
<http.port>
${liberty.var.http.port}
</http.port>
<https.port>
${liberty.var.https.port}
</https.port>
<cf.context.root>/converter</cf.context.root>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<server description="Sample Liberty server">

<featureManager>
<feature>pages-3.1</feature>
</featureManager>

<variable name="http.port" defaultValue="9080" />
<variable name="https.port" defaultValue="9443" />

<!-- tag::server[] -->
<httpEndpoint host="*" httpPort="${http.port}"
httpsPort="${https.port}" id="defaultHttpEndpoint" />

<!-- tag::EARdefinition[] -->
<enterpriseApplication id="guide-maven-multimodules-ear"
location="guide-maven-multimodules-ear.ear"
name="guide-maven-multimodules-ear" />
<!-- end::EARdefinition[] -->
<!-- end::server[] -->
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
// end::copyright[]
package it.io.openliberty.guides.multimodules;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.junit.jupiter.api.Test;

public class IT {
String port = System.getProperty("http.port");
String war = "converter";
String urlBase = "http://localhost:" + port + "/" + war + "/";

@Test
// tag::testIndexPage[]
public void testIndexPage() throws Exception {
String url = this.urlBase;
HttpURLConnection con = testRequestHelper(url, "GET");
assertEquals(200, con.getResponseCode(), "Incorrect response code from " + url);
assertTrue(testBufferHelper(con).contains("Enter the height in centimeters"),
"Incorrect response from " + url);
}
// end::testIndexPage[]

@Test
// tag::testHeightsPage[]
public void testHeightsPage() throws Exception {
String url = this.urlBase + "heights.jsp?heightCm=10";
HttpURLConnection con = testRequestHelper(url, "POST");
assertTrue(testBufferHelper(con).contains("3 inches"),
"Incorrect response from " + url);
}
// 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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2021 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.multimodules.lib;

public class Converter {

// tag::getFeetMethod[]
public static int getFeet(int cm) {
int feet = (int) (cm / 30.48);
return feet;
}
// end::getFeetMethod[]

// tag::getInchesMethod[]
public static int getInches(int cm) {
double feet = cm / 30.48;
int inches = (int) (cm / 2.54) - ((int) feet * 12);
return inches;
}
// end::getInchesMethod[]

public static int sum(int a, int b) {
return a + b;
}

public static int diff(int a, int b) {
return a - b;
}

public static int product(int a, int b) {
return a * b;
}

public static int quotient(int a, int b) {
return a / b;
}

}
Loading
Loading