Maven- Aufbau eines JEE Projekts

Automatisches Deployment ist so eine Herausforderung die man nicht einfach mal so nebenher macht. Allgemein gesehen geht es recht fix wenn man mal verstanden hat wie alles funktioniert.

Zum einen wird ein funktionsfähiges Maven Projektgruppe benötigt. Das heißt eine JEE Anwendung mit ihren Komponenten:

  • JPA
  • EJB
  • Web
  • EAR

Container. Das Ganze mit vernünftigen pom.xml Files die auch richtig funktionieren.

POM.XML für  JPA Projekt.

<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>com.kuw.example</groupId>
  <artifactId>ExampleJPA</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>ExampleJPA</name>
  <description>Java Persistence for Example</description>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
		<groupId>org.eclipse.persistence</groupId>
		<artifactId>eclipselink</artifactId>
		<version>2.5.0</version>
	</dependency>
  </dependencies>
</project>

POM.XML für EJB Projekt:

<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>com.kuw.example</groupId>
  <artifactId>ExampleEJB</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>ejb</packaging>
  <build>
    <sourceDirectory>ejbModule</sourceDirectory>
    <resources>
      <resource>
        <directory>ejbModule</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-ejb-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <ejbVersion>3.1</ejbVersion>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
  	<dependency>
	 	<groupId>com.kuw.example</groupId>
		<artifactId>ExampleJPA</artifactId>
		<version>${project.version}</version>
		<scope>provided</scope>
		<type>jar</type>
	</dependency>   
	<dependency>
		<groupId>javax.mail</groupId>
		<artifactId>mail</artifactId>
		<version>1.4.7</version>
	</dependency>
	<dependency>
		<groupId>org.apache.commons</groupId>
	  	<artifactId>commons-lang3</artifactId>
	  	<version>3.1</version>
	</dependency>
	<dependency>
		<groupId>org.eclipse.persistence</groupId>
		<artifactId>eclipselink</artifactId>
		<version>2.5.0</version>
	</dependency>
	<dependency>
		<groupId>javax.ejb</groupId>
		<artifactId>javax.ejb-api</artifactId>
		<version>3.2</version>
	</dependency>
  </dependencies>
  <name>QuatEJB</name>
</project>

POM.XML für Web Projekt inkl. Primefaces

<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>com.kuw.example</groupId>
  <artifactId>Example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>Quat</name>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
	  <dependency>
		<groupId>javax.faces</groupId>
		<artifactId>jsf-api</artifactId>
		<version>2.1</version>
	</dependency>
  	<dependency>
  		<groupId>org.apache.directory.studio</groupId>
  		<artifactId>org.apache.commons.io</artifactId>
  		<version>2.4</version>
  	</dependency>
  	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>1.3</version>
	</dependency>
	<dependency>
	 	<groupId>com.kuw.example</groupId>
		<artifactId>ExampleEJB</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<scope>provided</scope>
		<type>ejb</type>
	</dependency>
	<dependency>
	 	<groupId>com.kuw.example</groupId>
		<artifactId>ExampleJPA</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<scope>provided</scope>
		<type>jar</type>
	</dependency>
  	<dependency>
		<groupId>org.primefaces.extensions</groupId>
		<artifactId>primefaces-extensions</artifactId>
		<version>0.7.1</version>
	</dependency>
   <dependency>
		<groupId>org.primefaces.extensions</groupId>
		<artifactId>resources-ckeditor</artifactId>
		<version>0.7.1</version>
	</dependency>
	<dependency>
		<groupId>org.primefaces.extensions</groupId>
		<artifactId>resources-codemirror</artifactId>
		<version>0.7.1</version>
	</dependency>
		<dependency>
		<groupId>org.primefaces.extensions</groupId>
		<artifactId>all-themes</artifactId>
		<version>1.0.8</version>
	</dependency>
    <dependency>  
	    <groupId>org.primefaces</groupId>  
	    <artifactId>primefaces</artifactId>  
	    <version>3.5</version>  
	</dependency>                                 
  </dependencies>
  <repositories>
	<repository>  
	    <id>prime-repo</id>  
	    <name>PrimeFaces Maven Repository</name>  
	    <url>http://repository.primefaces.org</url>  
	    <layout>default</layout>  
	</repository>  
  </repositories>
</project>

POM.XML für EAR.

<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>com.kuw.example</groupId>
  <artifactId>ExampleEAR</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>ear</packaging>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.8</version>
        <configuration>
          <earSourceDirectory>EarContent</earSourceDirectory>
          <generateApplicationXml>false</generateApplicationXml>
          <version>6</version>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <name>ExampleEAR</name>
  <url>www.ka-und-we.de</url>
  <dependencies>
  	<dependency>
  		<groupId>com.kuw.example</groupId>
  		<artifactId>ExampleEJB</artifactId>
  		<version>${project.version}</version>
  		<type>ejb</type>
  	</dependency>
  	<dependency>
  		<groupId>com.kuw.example</groupId>
  		<artifactId>QsMPrime</artifactId>
  		<version>${project.version}</version>
  		<type>war</type>
  	</dependency>
  	<dependency>
  		<groupId>com.kuw.example</groupId>
  		<artifactId>ExampleJPA</artifactId>
  		<version>${project.version}</version>
  		<type>war</type>
  	</dependency>
  </dependencies>
</project>

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.