JBoss EAP 배포를 위한 애플리케이션 개발 시작하기

Red Hat JBoss Enterprise Application Platform 8.0

JBoss EAP 배포를 위한 애플리케이션 생성을 시작합니다.

Red Hat Customer Content Services

초록

Maven을 프로젝트 관리 도구로 사용하여 JBoss EAP 배포용 애플리케이션 생성을 시작합니다. 베어 메탈 또는 OpenShift Container Platform에서 실행되는 JBoss EAP에 애플리케이션을 배포하십시오.

JBoss EAP 문서에 대한 피드백 제공

오류를 보고하거나 문서를 개선하기 위해 Red Hat Jira 계정에 로그인하여 문제를 제출하십시오. Red Hat Jira 계정이 없는 경우 계정을 생성하라는 메시지가 표시됩니다.

프로세스

  1. 티켓을 생성하려면 다음 링크를 클릭하십시오.
  2. 요약 에 문제에 대한 간략한 설명을 입력합니다.
  3. 설명에서 문제 또는 개선 사항에 대한 자세한 설명을 제공합니다. 문서에서 문제가 발생한 위치에 URL을 포함합니다.
  4. Submit 을 클릭하고 문제를 적절한 문서 팀으로 라우팅합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 용어를 교체하기 위해 최선을 다하고 있습니다. 먼저 마스터(master), 슬레이브(slave), 블랙리스트(blacklist), 화이트리스트(whitelist) 등 네 가지 용어를 교체하고 있습니다. 이러한 변경 작업은 작업 범위가 크므로 향후 여러 릴리스에 걸쳐 점차 구현할 예정입니다. 자세한 내용은 CTO Chris Wright의 메시지를 참조하십시오.

새로운 프로그래밍 언어 또는 기술에 익숙해지는 가장 좋은 방법은 "Hello World" 애플리케이션을 생성하는 것입니다. Maven을 프로젝트 관리 도구로 사용하여 JBoss EAP에 대한 "Hello World" 애플리케이션을 생성할 수 있습니다.

Hello World 애플리케이션을 생성하려면 애플리케이션을 배포하고 배포를 테스트하려면 다음 절차를 따르십시오.

1장. hello world 애플리케이션을 위한 Maven 프로젝트 생성

Maven 프로젝트에는 pom.xml 구성 파일이 포함되어 있으며 애플리케이션을 생성하는 데 필요한 디렉터리 구조가 있습니다. pom.xml 구성 파일을 구성하여 애플리케이션에 대한 종속성을 추가할 수 있습니다.

hello world 애플리케이션에 대한 Maven 프로젝트를 생성하려면 다음 절차를 따르십시오.

1.1. maven-archetype-webapp을 사용하여 Maven 프로젝트 생성

maven-archetype-webapp archetype을 사용하여 JBoss EAP 배포를 위한 애플리케이션을 구축하기 위한 Maven 프로젝트를 생성합니다. Maven은 프로젝트 유형과 관련된 템플릿을 기반으로 프로젝트를 생성하는 데 필요한 다양한 archetypes를 제공합니다. maven-archetype-webapp 은 간단한 웹 애플리케이션을 개발하는 데 필요한 구조를 사용하여 프로젝트를 생성합니다.

사전 요구 사항

프로세스

  1. mvn 명령을 사용하여 Maven 프로젝트를 설정합니다. 명령은 프로젝트에 대한 디렉터리 구조와 pom.xml 구성 파일을 생성합니다.

    $ mvn archetype:generate                          \
    -DgroupId=org.jboss.as.quickstarts                \1
    -DartifactId=helloworld                           \2
    -DarchetypeGroupId=org.apache.maven.archetypes    \3
    -DarchetypeArtifactId=maven-archetype-webapp      \4
    -DinteractiveMode=false                            5
    1
    groupID 는 프로젝트를 고유하게 식별합니다.
    2
    artifactId 는 생성된 Cryostat 아카이브 이름입니다.
    3
    maven-archetype-webappgroupID 입니다.
    4
    maven-archetype-webappartifactID 입니다.
    5
    Maven에 대화형 모드를 시작하는 대신 제공된 매개 변수를 사용하도록 지시합니다.
  2. 생성된 디렉터리로 이동합니다.

    $ cd helloworld
  3. 텍스트 편집기에서 생성된 pom.xml 구성 파일을 엽니다.
  4. <name> helloworld Maven Webapp</name > 행 뒤에 pom.xml 구성 파일의 < project > 섹션 내의 콘텐츠를 제거합니다.

    파일이 다음과 같이 표시되는지 확인합니다.

    <?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">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.jboss.as.quickstarts</groupId>
        <artifactId>helloworld</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>
        <name>helloworld Maven Webapp</name>
    
    </project>

    애플리케이션에 필요하지 않기 때문에 콘텐츠가 제거되었습니다.

1.2. Maven 프로젝트에서 속성 정의

Maven pom.xml 구성 파일에서 속성을 값의 위치 소유자로 정의할 수 있습니다. 구성에서 일관되게 값을 사용하려면 JBoss EAP 서버의 값을 속성으로 정의합니다.

사전 요구 사항

프로세스

  • &lt ;version.server& gt; 속성을 구성된 애플리케이션을 배포할 JBoss EAP 버전으로 정의합니다.

    <project>
        ...
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
            <version.server>8.0.0.GA-redhat-00009</version.server>
        </properties>
    </project>

1.3. Maven 프로젝트에서 리포지토리 정의

Maven이 다운로드할 아티팩트 및 플러그인을 찾는 아티팩트 및 플러그인 리포지토리를 정의합니다.

사전 요구 사항

프로세스

  1. 아티팩트 리포지토리를 정의합니다.

    <project>
        ...
        <repositories>
            <repository>                                                                1
                <id>jboss-public-maven-repository</id>
                <name>JBoss Public Maven Repository</name>
                <url>https://repository.jboss.org/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </snapshots>
                <layout>default</layout>
            </repository>
            <repository>                                                                2
                <id>redhat-ga-maven-repository</id>
                <name>Red Hat GA Maven Repository</name>
                <url>https://maven.repository.redhat.com/ga/</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </snapshots>
                <layout>default</layout>
            </repository>
        </repositories>
    </project>
    1
    Red Hat GA Maven 리포지토리는 모든 제품화된 JBoss EAP 및 기타 Red Hat 아티팩트를 제공합니다.
    2
    JBoss Public Maven Repository는 WildFly Maven 플러그인과 같은 아티팩트를 제공합니다.
  2. 플러그인 리포지토리를 정의합니다.

    <project>
        ...
        <pluginRepositories>
            <pluginRepository>
                <id>jboss-public-maven-repository</id>
                <name>JBoss Public Maven Repository</name>
                <url>https://repository.jboss.org/nexus/content/groups/public/</url>
                <releases>
                   <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>redhat-ga-maven-repository</id>
                <name>Red Hat GA Maven Repository</name>
                <url>https://maven.repository.redhat.com/ga/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </project>

1.4. Maven 프로젝트에서 JBoss EAP BOM을 종속성 관리로 가져오기

BBOM(Cancelish of materials)을 사용하여 JBoss EAP EE를 가져와서 런타임 Maven 종속 항목을 제어합니다. < dependencyManagement > 섹션에 BOM을 지정하는 경우 제공된 범위에 정의된 Maven 종속 항목의 버전을 개별적으로 지정할 필요가 없습니다.

사전 요구 사항

프로세스

  1. pom.xml 구성 파일의 properties 섹션에 BOM 버전의 속성을 추가합니다.

    <properties>
        ....
        <version.bom.ee>${version.server}</version.bom.ee>
    </properties>

    < version.server> 속성에 정의된 값은 BOM 버전의 값으로 사용됩니다.

  2. JBoss EAP BOMs 종속성 관리를 가져옵니다.

    <project>
        ...
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.bom</groupId>                 1
                    <artifactId>jboss-eap-ee-with-tools</artifactId> 2
                    <version>${version.bom.ee}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>
    1
    JBoss EAP 제공 BOM의 groupID.
    2
    지원되는 JBoss EAP Java EE API와 추가 JBoss EAP API JAR 및 클라이언트 BOMs, Arquillian과 같은 개발 툴을 제공하는 JBoss EAP 제공 BOM의 artifactId입니다.

1.5. Maven 프로젝트에서 플러그인 관리 추가

Maven 플러그인 관리 섹션을 pom.xml 구성 파일에 추가하여 Maven CLI 명령에 필요한 플러그인을 가져옵니다.

사전 요구 사항

프로세스

  1. < properties> 섹션에서 wildfly-maven-pluginmaven-war-plugin 의 버전을 정의합니다.

    <properties>
        ...
        <version.plugin.wildfly>4.1.1.Final</version.plugin.wildfly>
        <version.plugin.war>3.3.2</version.plugin.war>
    </properties>
  2. &lt ; project> 섹션의 < build > 섹션에 <pluginManagement > 를 추가합니다.

    <project>
        ...
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>    1
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <version>${version.plugin.wildfly}</version>
                    </plugin>
                    <plugin>                                  2
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>${version.plugin.war}</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </project>
    1
    wildfly-maven-plugin 을 사용하여 wildfly:deploy 명령을 사용하여 애플리케이션을 JBoss EAP에 배포할 수 있습니다.
    2
    JDK17+와의 호환성을 보장하기 위해 war 플러그인 버전을 관리해야 합니다.

1.6. maven 프로젝트 확인

빌드를 구성한 Maven 프로젝트가 있는지 확인합니다.

사전 요구 사항

프로세스

  • pom.xml 에 추가된 Maven 종속성을 로컬로 설치합니다.

    $ mvn package

    다음과 유사한 출력이 표시됩니다.

    ...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    ...

2장. 안녕하세요 세계 서블릿 생성

액세스할 때 "Hello world!"를 반환하는 서블릿을 만듭니다.

이 절차에서 &lt ;application_home >은 애플리케이션의 pom.xml 구성 파일이 포함된 디렉터리를 나타냅니다.

사전 요구 사항

프로세스

  1. <dependency Management> 섹션 뒤에 pom.xml 구성 파일에 필요한 종속성 을 추가합니다.

    <project>
        ...
        <dependencies>
            <dependency>                                             1
                <groupId>jakarta.servlet</groupId>
                <artifactId>jakarta.servlet-api</artifactId>
                <scope>provided</scope>                              2
            </dependency>
        </dependencies>
    1
    Jakarta.servlet-api 종속성은 Jakarta Servlet API를 제공합니다.
    2
    애플리케이션에 종속성이 포함되지 않도록 제공된 대로 범위를 정의합니다. 애플리케이션에 종속성을 포함하지 않는 이유는 이 종속성은 jboss-eap-ee-with-tools BOM에 의해 관리되며 이러한 종속 항목은 JBoss EAP에 포함되어 있기 때문입니다.
    참고

    jboss-eap-ee-with-tools BOM이 < dependencyManagement > 섹션에서 가져오기 때문에 종속성은 버전 없이 정의됩니다.

  2. < application_home> 디렉터리 로 이동합니다.
  3. Java 파일을 저장할 디렉터리를 만듭니다.

    $ mkdir -p src/main/java/org/jboss/as/quickstarts/helloworld
  4. 새 디렉터리로 이동합니다.

    $ cd src/main/java/org/jboss/as/quickstarts/helloworld
  5. "Hello World!"를 반환하는 서블릿 HelloWorldServlet.java 를 만듭니다.

    package org.jboss.as.quickstarts.helloworld;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import jakarta.servlet.ServletException;
    import jakarta.servlet.annotation.WebServlet;
    import jakarta.servlet.http.HttpServlet;
    import jakarta.servlet.http.HttpServletRequest;
    import jakarta.servlet.http.HttpServletResponse;
    
    @WebServlet("/HelloWorld")                      1
    public class HelloWorldServlet extends HttpServlet {
    
        static String PAGE_HEADER = "<html><head><title>helloworld</title></head><body>";
    
        static String PAGE_FOOTER = "</body></html>";
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setContentType("text/html");
            PrintWriter writer = resp.getWriter();
            writer.println(PAGE_HEADER);
            writer.println("<h1> Hello World! </h1>");
            writer.println(PAGE_FOOTER);
            writer.close();
        }
    }
    1
    @WebServlet("/HelloWorld") 주석은 JBoss EAP에 다음 정보를 제공합니다.
    • 이 클래스는 서블릿입니다.
    • URL " <application_URL> /HelloWorld"에서 서블릿을사용할 수 있도록 설정합니다.

      예를 들어 JBoss EAP가 localhost에서 실행 중이고 기본 HTTP 포트 8080에서 사용할 수 있는 경우 URL은 http://localhost:8080/helloworld/HelloWorld 입니다.

  6. < application_home> /src/main/webapp 디렉터리로 이동합니다.

    Maven에서 생성한 "index.jsp" 파일을 찾습니다. 이 파일은 애플리케이션에 액세스할 때 "Hello World!"를 출력합니다.

  7. 콘텐츠를 다음 콘텐츠로 교체하여 Hello World 서블릿으로 리디렉션하도록 "index.jsp" 파일을 업데이트합니다.

    <html>
        <head>
            <meta http-equiv="Refresh" content="0; URL=HelloWorld">
        </head>
    </html>
  8. < application_home> 디렉터리 로 이동합니다.
  9. 다음 명령을 사용하여 애플리케이션을 WAR(웹 아카이브)로 컴파일하고 패키징합니다.

    $ mvn package

    출력 예

    ...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    ...

3장. 서버에 애플리케이션 배포

베어 메탈 또는 OpenShift Container Platform에서 실행되는 JBoss EAP 서버에 애플리케이션을 배포할 수 있습니다.

베어 메탈에서 실행되는 JBoss EAP 서버에 애플리케이션을 배포하려면 다음 절차를 따르십시오.

OpenShift Container Platform에서 실행되는 JBoss EAP 서버에 애플리케이션을 배포하려면 다음 절차를 따르십시오.

3.1. 베어 메탈 설치에 애플리케이션 배포

JBoss EAP 배포 플러그인을 사용하여 JBoss EAP에 애플리케이션을 배포할 수 있습니다.

사전 요구 사항

프로세스

  1. 애플리케이션 루트 디렉터리로 이동합니다.

    애플리케이션 루트 디렉터리에는 pom.xml 구성 파일이 포함되어 있습니다.

  2. 다음 빌드 구성을 < project > 섹션에 있는 pom.xml 구성 파일에 추가하여 애플리케이션 아카이브 파일 이름을 정의합니다.

    <build>
        ...
        <finalName>${project.artifactId}</finalName>        1
    </build>
    1
    배포 이름을 프로젝트의 아티팩트 ID로 설정합니다.
  3. JBoss EAP 배포 플러그인을 사용하여 애플리케이션을 빌드하고 배포합니다.

    $ mvn package wildfly:deploy

검증

3.2. OpenShift Container Platform에 애플리케이션 배포

S2I(Source-to-Image) 워크플로를 사용하여 OpenShift Container Platform의 JBoss EAP에 애플리케이션을 배포할 수 있습니다. S2I 워크플로는 Git 리포지토리에서 소스 코드를 가져와 사용하려는 언어 및 프레임워크를 기반으로 하는 컨테이너에 삽입합니다. S2I 워크플로가 완료되면 src 코드가 컴파일되고 애플리케이션이 패키지화되고 JBoss EAP 서버에 배포됩니다.

3.2.1. OpenShift Container Platform에 배포할 애플리케이션 준비

OpenShift Container Platform은 Git 리포지토리에서 호스팅되는 애플리케이션을 사용합니다. OpenShift에 애플리케이션을 배포하려면 먼저 Git 리포지토리로 애플리케이션을 푸시해야 합니다. 그 후 JBoss EAP helm 차트를 사용하여 애플리케이션 배포를 구성할 수 있습니다.

사전 요구 사항

  • 애플리케이션을 생성했습니다.

    자세한 내용은 Hello World 서블릿 생성을 참조하십시오.

  • Git 리포지토리가 생성되어 있습니다.

프로세스

  1. 아직 없는 경우 애플리케이션을 로컬 Git 리포지토리로 이동합니다.

    $ mv -r helloworld/ <your_git_repo>
  2. pom.xml 구성 파일에 다음 속성을 정의합니다.

    <properties>
        ...
        <version.plugin.eap>1.0.0.Final-redhat-00013</version.plugin.eap> 1
    </properties>
    1
    <version.plugin.eap >은 JBoss EAP Maven 플러그인의 버전을 정의합니다.
  3. < project > 섹션의 < build > 섹션에서 JBoss EAP maven 플러그인을 < pluginManagement >에 추가합니다.

    <project>
        ...
        <build>
            <pluginManagement>
                <plugins>
                    ...
                    <plugin>
                        <groupId>org.jboss.eap.plugins</groupId>
                        <artifactId>eap-maven-plugin</artifactId>
                        <version>${version.plugin.eap}</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </project>
  4. pom.xml 구성 파일에 "openshift" 프로필을 생성합니다.

    이 프로필은 OpenShift Container Platform에 배포하는 데 필요한 플러그인, 기능 팩 및 계층을 정의합니다.

    <profiles>
        <profile>
            <id>openshift</id>
            <build>
                <plugins>
                    <plugin>
                         <groupId>org.jboss.eap.plugins</groupId>
                         <artifactId>eap-maven-plugin</artifactId>     1
                         <configuration>
                             <channels>
                                 <channel>
                                     <manifest>
                                         <groupId>org.jboss.eap.channels</groupId>
                                         <artifactId>eap-8.0</artifactId>
                                     </manifest>
                                 </channel>
                             </channels>
                             <feature-packs>
                                 <feature-pack>                            2
                                     <location>org.jboss.eap:wildfly-ee-galleon-pack</location>
                                 </feature-pack>
                                 <feature-pack>
                                     <location>org.jboss.eap.cloud:eap-cloud-galleon-pack</location>
                                 </feature-pack>
                             </feature-packs>
                             <layers>                                      3
                                 <layer>cloud-server</layer>
                             </layers>
                             <name>ROOT.war</name>                         4
                         </configuration>
                         <executions>
                             <execution>
                                 <goals>
                                     <goal>package</goal>
                                 </goals>
                             </execution>
                         </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    1
    Wildfly-maven-plugin 은 OpenShift Container Platform에 배포된 애플리케이션을 사용하여 JBoss EAP 인스턴스를 프로비저닝하기 위한 JBoss EAP 플러그인입니다.
    2
    feature-packs 는 기능을 정의합니다(서버를 동적으로 프로비저닝하는 기능이 포함된 파일의 압축을 풉니다). 이 경우 feature-packs org.wildfly:wildfly-galleon-packorg.wildfly.cloud:wildfly-galleon-pack 이 필요합니다.
    3
    계층 은 프로비저닝된 서버에 포함할 계층(구성된 기능 팩에서)을 정의합니다. 각 계층은 자체적으로 설치하거나 다른 계층과 함께 설치할 수 있는 하나 이상의 서버 기능을 식별합니다. Red Hat은 클라우드 서버에 적합한 JBoss EAP의 기본 기능만 프로비저닝하는 cloud-server 계층을 선택합니다.
    4
    <name>ROOT.war</name >: 애플리케이션의 웹 아카이브(WAR)의 결과 이름을 정의합니다. ROOT.war 가 지정되면 애플리케이션이 서버의 루트 경로에 배포됩니다. 그렇지 않으면 < name/> 상대 경로에 배포됩니다.
  5. 애플리케이션이 컴파일되는지 확인합니다.

    $ mvn package -Popenshift
  6. 변경 사항을 리포지토리로 내보냅니다.

3.2.2. Helm을 사용하여 OpenShift의 JBoss EAP에 애플리케이션 배포

JBoss EAP Helm 차트를 사용하여 Helm을 사용하여 OpenShift의 JBoss EAP에 애플리케이션을 구성하고 배포합니다.

사전 요구 사항

프로세스

  1. 애플리케이션 root directoy에 charts 라는 디렉터리를 생성하고 해당 디렉터리로 이동합니다. 애플리케이션 루트 디렉터리는 pom.xml 구성 파일이 포함된 디렉터리입니다.

    $ mkdir charts; cd charts
  2. 다음 콘텐츠를 사용하여 helm.yaml 파일을 생성합니다.

    build:
      uri: https://github.com/<user>/<repository>.git     1
      ref: <branch_name>                                  2
      contextDir: helloworld                              3
    deploy:
      replicas: 1                                         4
    1
    OpenShift Container Platform에 배포할 애플리케이션이 포함된 Git 리포지토리의 URL을 지정합니다.
    2
    애플리케이션이 포함된 Git 분기를 지정합니다.
    3
    애플리케이션이 포함된 디렉터리를 지정합니다.
    4
    생성할 Pod 수를 지정합니다.
  3. Helm에 JBoss EAP 리포지토리를 구성합니다.

    • 이전에 JBoss EAP 리포지토리를 Helm에 추가하지 않은 경우 추가합니다.

      $ helm repo add jboss-eap https://jbossas.github.io/eap-charts/
    • JBoss EAP 리포지토리를 Helm에 이미 추가한 경우 업데이트합니다.

      $ helm repo update jboss-eap
  4. helm를 사용하여 애플리케이션을 배포합니다.

    $ helm install helloworld -f helm.yaml jboss-eap/eap8

    배포를 완료하는 데 몇 분이 걸릴 수 있습니다.

검증

  1. 배포에 대한 경로의 URL을 가져옵니다.

    $ APPLICATION_URL=https://$(oc get route helloworld --template='{{ .spec.host }}') &&
    echo "" &&
    echo "Application URL: $APPLICATION_URL"
  2. 브라우저에서 "Application URL"으로 이동합니다.

    "/HelloWorld" 경로의 서블릿으로 리디렉션되고 다음 메시지가 표시됩니다.

    Hello World!

4장. JBoss EAP에 배포된 애플리케이션 테스트

JBoss EAP에 배포된 Hello World 애플리케이션이 작동하는지 확인하려면 통합 테스트를 추가할 수 있습니다.

베어 메탈에서 실행되는 JBoss EAP 서버에 배포된 애플리케이션에 대한 테스트를 추가하려면 다음 절차를 따르십시오.

OpenShift Container Platform에서 실행되는 JBoss EAP 서버에 배포된 애플리케이션에 대한 테스트를 추가하려면 다음 절차를 따르십시오.

4.1. 통합 테스트에 필요한 Maven 종속성 및 프로필 추가

애플리케이션에 대한 통합 테스트를 생성하려면 필요한 Maven 종속성을 추가합니다.

사전 요구 사항

프로세스

  1. pom.xml 구성 파일에 다음 속성을 정의합니다.

    <properties>
        ...
        <version.plugin.failsafe>3.2.2</version.plugin.failsafe>
    </properties>
  2. 테스트에 필요한 종속성을 추가합니다.

    <project>
        ...
        <dependencies>
            ...
            <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <scope>test</scope>
            </dependency>
        </dependencies>
    </project>
  3. 통합 테스트에 필요한 플러그인을 추가하도록 프로필을 정의합니다.

    <project>
        ...
        <profiles>
        ...
            <profile>
                <id>integration-testing</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId> 1
                            <version>${version.plugin.failsafe}</version>
                            <configuration>
                                <includes>
                                    <include>**/HelloWorldServletIT</include>       2
                                </includes>
                            </configuration>
                            <executions>
                                <execution>
                                   <goals>
                                       <goal>integration-test</goal>
                                       <goal>verify</goal>
                                   </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    </project>
    1
    통합 테스트 실행을 위한 Maven 플러그인입니다.
    2
    애플리케이션을 테스트하는 Java 클래스의 이름입니다.

4.2. 애플리케이션을 테스트할 테스트 클래스 생성

웹 페이지의 HTTP GET에서 200 OK를 반환하는지 확인하여 애플리케이션이 OpenShift Container Platform의 JBoss EAP에 배포되고 실행되고 있는지 확인하는 통합 테스트를 생성합니다.

이 절차에서 &lt ;application_home >은 애플리케이션의 pom.xml 구성 파일이 포함된 디렉터리를 나타냅니다.

사전 요구 사항

프로세스

  1. < application_home> 디렉터리 로 이동합니다.
  2. 테스트 클래스를 저장할 디렉터리를 만듭니다.

    $ mkdir -p src/test/java/org/jboss/as/quickstarts/helloworld
  3. 새 디렉터리로 이동합니다.

    $ cd src/test/java/org/jboss/as/quickstarts/helloworld
  4. 배포를 테스트하는 Java 클래스 HelloWorldServletIT.java 를 생성합니다.

    package org.jboss.as.quickstarts.helloworld;
    
    import org.junit.Test;
    import java.io.IOException;
    import java.net.URI;
    import java.net.URISyntaxException;
    import java.net.http.HttpClient;
    import java.net.http.HttpRequest;
    import java.net.http.HttpResponse;
    import java.time.Duration;
    import static org.junit.Assert.assertEquals;
    
    public class HelloWorldServletIT {
    
        private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/helloworld";                1
    
        @Test
        public void testHTTPEndpointIsAvailable() throws IOException, InterruptedException, URISyntaxException {
            String serverHost = System.getProperty("server.host");
            if (serverHost == null) {
                serverHost = DEFAULT_SERVER_HOST;
            }
            final HttpRequest request = HttpRequest.newBuilder()
                    .uri(new URI(serverHost+"/HelloWorld"))
                    .GET()
                    .build();                                                                                 2
            final HttpClient client = HttpClient.newBuilder()
                    .followRedirects(HttpClient.Redirect.ALWAYS)
                    .connectTimeout(Duration.ofMinutes(1))
                    .build();                                                                                 3
            final HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); 4
            assertEquals(200, response.statusCode());                                                         5
        }
    }
    1
    애플리케이션이 실행 중인 URL입니다. 이 값은 sever.host 가 정의되지 않은 경우 사용됩니다.
    2
    애플리케이션 URI에 대한 CryostatRequest 인스턴스를 생성합니다.
    3
    애플리케이션에 대한 요청을 보내고 애플리케이션에서 응답을 받을 수 있는 CryostatClient를 만듭니다.
    4
    애플리케이션에서 응답을 가져옵니다.
    5
    애플리케이션에서 다시 수신되는 응답이 "200"이 애플리케이션을 다시 예약할 수 있음을 나타내는지 테스트합니다.

다음 단계

4.3. 베어 메탈에서 실행 중인 JBoss EAP에 배포된 애플리케이션 테스트

베어 메탈에서 실행 중인 JBoss EAP에 배포된 애플리케이션을 테스트합니다.

사전 요구 사항

프로세스

  1. < application_home> 디렉터리 로 이동합니다.
  2. 통합 테스트 프로필과 함께 verify 명령을 사용하여 통합 테스트를 실행합니다.

    $ mvn verify -Pintegration-testing

    출력 예

    [INFO]
    [INFO] Results:
    [INFO]
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    [INFO]
    [INFO]
    [INFO] --- maven-failsafe-plugin:3.2.2:verify (default) @ helloworld ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  9.982 s
    [INFO] Finished at: 2023-11-22T14:53:54+05:30
    [INFO] ------------------------------------------------------------------------

4.4. OpenShift Container Platform의 JBoss EAP에 배포된 애플리케이션 테스트

OpenShift Container Platform의 JBoss EAP에 배포된 애플리케이션을 테스트합니다.

사전 요구 사항

프로세스

  1. Git 리포지토리로 변경 사항을 내보냅니다.
  2. < application_home> 디렉터리 로 이동합니다.
  3. verify 명령을 사용하여 테스트를 실행하고 통합 테스트 프로필을 활성화하고 애플리케이션에 URL을 지정하여 테스트를 실행합니다.

    $ mvn verify -Pintegration-testing -Dserver.host=https://$(oc get route helloworld --template='{{ .spec.host }}')
    참고

    테스트에서는 SSL/TLS를 사용하여 배포된 애플리케이션에 연결합니다. 따라서 테스트가 실행되는 시스템에서 인증서를 신뢰해야 합니다.

    인증서를 신뢰하려면 Java 신뢰 저장소에 인증서를 추가해야 합니다.

    예제

    $ keytool -trustcacerts -keystore _<path-to-java-truststore>_ -storepass _<trust-store-password>_ -importcert -alias _<alias-for-the-certificate>_ -file _<path-to-certificate>_/_<certificate-name>_

    출력 예

    [INFO] Running org.jboss.as.quickstarts.helloworld.HelloWorldServletIT
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.345 s -- in org.jboss.as.quickstarts.helloworld.HelloWorldServletIT
    [INFO]
    [INFO] Results:
    [INFO]
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    [INFO]
    [INFO]
    [INFO] --- maven-failsafe-plugin:3.2.2:verify (default) @ helloworld ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  2.984 s
    [INFO] Finished at: 2023-11-30T15:51:22+05:30
    [INFO] ------------------------------------------------------------------------





2024-02-08에 최종 업데이트된 문서

법적 공지

Copyright © 2024 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.