Maven2 : 모범 사례 (EAR 파일)
Ant에서 Maven으로 전환 중이며 EAR 파일 기반 Enterprise 프로젝트를 설정하는 모범 사례를 구축하고 있습니다?
EJB 용 jar 파일, 웹 계층 용 WAR 파일 및 해당 배포 설명자와 캡슐화 EAR 파일을 사용하여 꽤 표준 프로젝트를 만들고 싶다고 가정 해 보겠습니다.
어떻게해야합니까? archetypeArtifactId=maven-archetype-webapp
war 파일로 프로젝트를 만들고 나서 확장할까요? 이에 가장 많은 프로젝트 구조 (및 POM 파일 예)는 무엇입니까? ear 파일 관련 배포 설명자 등을 어디에 고정 할당합니까?
감사합니다.
새 프로젝트를 만듭니다. 새 프로젝트는 EJB 및 WAR 프로젝트에 대한 두 가지 프로젝트를 포함하는 EAR 어셈블리 프로젝트입니다.
여기에 실제로 세 개의 메이븐 프로젝트가 있습니다. 하나의 EJB. 하나의 전쟁. 두 부분을 함께 귀를 만드는 하나의 EAR.
배포 설명자는 maven에서 생성하거나 EAR 프로젝트 구조의 리소스 디렉터리에 배치 할 수 있습니다.
maven-ear-plugin은 구성하는 데 사용하는 문서 는 일반적으로 maven이 작동하지만 작동하는 것이 확실하고 명확하지 않습니다.
따라서 예를 들어 다음과 같이 할 수 있습니다.
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>myEar</artifactId>
<packaging>ear</packaging>
<name>My EAR</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>1.4</version>
<modules>
<webModule>
<groupId>com.mycompany</groupId>
<artifactId>myWar</artifactId>
<bundleFileName>myWarNameInTheEar.war</bundleFileName>
<contextRoot>/myWarConext</contextRoot>
</webModule>
<ejbModule>
<groupId>com.mycompany</groupId>
<artifactId>myEjb</artifactId>
<bundleFileName>myEjbNameInTheEar.jar</bundleFileName>
</ejbModule>
</modules>
<displayName>My Ear Name displayed in the App Server</displayName>
<!-- If I want maven to generate the application.xml, set this to true -->
<generateApplicationXml>true</generateApplicationXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>myEarName</finalName>
</build>
<!-- Define the versions of your ear components here -->
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myWar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myEjb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
</project>
저에게 많은 도움이되는 것은 Maven archetype : generate 목표를 실행하고 아키 타입 중 하나를 선택하는 것이되지만, 그중 일부는 포함되는 업데이트되는 것 (JBoss가 잘되는 것입니다).
mvn archetype:generate
수백 개의 아키 타입이 선택 가능한 번호 목록에 나타났습니다 (현재 519 개!). 여전히 실행중인 목표는 숫자를 입력하거나 검색 문자열을 입력하여 선택하라는 메시지를 표시했습니다. 예 :
513: remote -> org.xwiki.commons:xwiki-commons-component-archetype
514: remote -> org.xwiki.rendering:xwiki-rendering-archetype-macro
515: remote -> org.zkoss:zk-archetype-component
516: remote -> org.zkoss:zk-archetype-webapp
517: remote -> ru.circumflex:circumflex-archetype (-)
518: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):
검색 문자열 "ear"를 입력하여 목록을 8 개 항목으로 줄였습니다 (오늘 기준).
Choose archetype:
1: remote -> org.codehaus.mojo.archetypes:ear-j2ee14 (-)
2: remote -> org.codehaus.mojo.archetypes:ear-javaee6 (-)
3: remote -> org.codehaus.mojo.archetypes:ear-jee5 (-)
4: remote -> org.hibernate:hibernate-search-quickstart (-)
5: remote -> org.jboss.spec.archetypes:jboss-javaee6-ear-webapp
6: remote -> org.jboss.spec.archetypes:jboss-javaee6-webapp-ear-archetype
7: remote -> org.jboss.spec.archetypes:jboss-javaee6-webapp-ear-archetype-blank
8: remote -> org.ow2.weblab.tools.maven:weblab-archetype-searcher
나는 "org.jboss.spec.archetypes : jboss-javaee6-ear-webapp"을 선택했습니다 (이 예에서는 선택 "5"를 입력함으로써).
다음으로 목표는 groupId, artifactId, 패키지 이름 등을 입력하도록 요청했고, 다음과 같이 잘 문서화 된 예제 애플리케이션을 생성했습니다.
[pgarner@localhost Foo]$ tree
.
|-- Foo-ear
| `-- pom.xml
|-- Foo-ejb
| |-- pom.xml
| `-- src
| |-- main
| | |-- java
| | | `-- com
| | | `-- foo
| | | |-- controller
| | | | `-- MemberRegistration.java
| | | |-- data
| | | | `-- MemberListProducer.java
| | | |-- model
| | | | `-- Member.java
| | | `-- util
| | | `-- Resources.java
| | `-- resources
| | |-- import.sql
| | `-- META-INF
| | |-- beans.xml
| | `-- persistence.xml
| `-- test
| |-- java
| | `-- com
| | `-- foo
| | `-- test
| | `-- MemberRegistrationTest.java
| `-- resources
|-- Foo-web
| |-- pom.xml
| `-- src
| `-- main
| |-- java
| | `-- com
| | `-- foo
| | `-- rest
| | |-- JaxRsActivator.java
| | `-- MemberResourceRESTService.java
| `-- webapp
| |-- index.html
| |-- index.xhtml
| |-- resources
| | |-- css
| | | `-- screen.css
| | `-- gfx
| | |-- banner.png
| | `-- logo.png
| `-- WEB-INF
| |-- beans.xml
| |-- faces-config.xml
| `-- templates
| `-- default.xhtml
|-- pom.xml
`-- README.md
32 directories, 23 files
주석이 잘 달린 4 개의 POM 파일을 읽은 후 필요한 정보를 거의 모두 얻었습니다.
./pom.xml
./Foo-ear/pom.xml
./Foo-ejb/pom.xml
./Foo-web/pom.xml
나는 좋은 (또는 모범 사례) 시작 프로젝트 구조라고 생각하는 것을 보여주기 위해 github 저장소를 만들었습니다.
https://github.com/StefanHeimberg/stackoverflow-1134894
일부 키워드 :
- 메이븐 3
- BOM (자체 종속성의 종속성 관리)
- 모든 프로젝트의 상위 (외부 종속성의 종속성 관리 및 글로벌 프로젝트 구성의 경우 PluginManagement)
- JUnit / Mockito / DBUnit
- 종속성이 EAR / lib 폴더에 있기 때문에 WEB-INF / lib없이 Clean War 프로젝트.
- 깨끗한 귀 프로젝트.
- Java EE7에 대한 최소 배포 설명자
- @LocalBean이 충분하므로 로컬 EJB 인터페이스가 없습니다.
- Maven 사용자 속성을 통한 최소 Maven 구성
- Servlet 3.1 / EJB 3.2 / JPA 2.1의 실제 배포 설명자
- 아키텍처 규칙을 확인하기 위해 macker-maven-plugin 사용
- 통합 테스트가 활성화되었지만 건너 뛰었습니다. (skipITs = false) CI 빌드 서버에서 활성화하는 데 유용합니다.
Maven 출력 :
Reactor Summary:
MyProject - BOM .................................... SUCCESS [ 0.494 s]
MyProject - Parent ................................. SUCCESS [ 0.330 s]
MyProject - Common ................................. SUCCESS [ 3.498 s]
MyProject - Persistence ............................ SUCCESS [ 1.045 s]
MyProject - Business ............................... SUCCESS [ 1.233 s]
MyProject - Web .................................... SUCCESS [ 1.330 s]
MyProject - Application ............................ SUCCESS [ 0.679 s]
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 8.817 s
Finished at: 2015-01-27T00:51:59+01:00
Final Memory: 24M/207M
------------------------------------------------------------------------
NetBeans IDE는 Patrick Garner가 제안한 것과 거의 유사한 구조를 자동으로 정의합니다. NetBeans 사용자의 경우
파일 -> 새 프로젝트 -> 왼쪽에서 선택 메이븐을 하고 오른쪽에서 선택 메이븐 엔터프라이즈 응용 프로그램 을 누릅니다 다음 -> 전쟁, EJB 및 설정 모두를위한 프로젝트 이름을 요청합니다.
IDE가 자동으로 구조를 생성합니다.
이것은 maven-ear-plugin 부분 의 좋은 예입니다 .
예제로 사용할 수 있는 maven archetype 을 확인할 수도 있습니다. mvn archetype : generate를 실행하면 사용 가능한 아키 타입 목록이 표시됩니다. 그들 중 하나는
maven-archetype-j2ee-simple
나는 완전한 maven 기반 귀 패키지 응용 프로그램의 종단 간 예제를 높고 낮게 검색하고 마침내 이것을 발견 했습니다 . 지침에는 CLI를 통해 실행할 때 옵션 2를 선택하라는 내용이 나와 있지만 용도에 따라 옵션 1을 사용하십시오.
참고 URL : https://stackoverflow.com/questions/1134894/maven2-best-practice-for-enterprise-project-ear-file
'IT' 카테고리의 다른 글
주어진 위도 / 경도 위치에 대한 경계 상자를 계산하는 방법은 무엇입니까? (0) | 2020.08.25 |
---|---|
PHP에서“do something OR DIE ()”는 작동 작동 중에 있습니까? (0) | 2020.08.25 |
Spring boot를 사용하여 프로그래밍 방식으로 현재 활성 프로필을 결정하는 방법 (0) | 2020.08.25 |
ASP.NET MVC- 비즈니스 조종이 컨트롤러에 있습니까? (0) | 2020.08.25 |
IPython 종료 확인 (0) | 2020.08.25 |