Per fare questo bisogna prima di tutto scricare la versione full dell'application server e ricordarsi di avviarlo con il comando: $JBOSS_HOME/bin/standalone.sh -server-config standalone-preview.xml
Standalone-preview.xml è il file di configurazione comprendente tutti i sottosistemi attivati per il profilo full.
Nella documentazione, però, non è chiaro quale sia la dipendenza corretta da introdurre con maven per avere a disposizione annotazioni e classi. Spulciando nel repository di jboss si nota che la dipendenza corretta è questa:
<dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-6.0</artifactId> <version>2.0.0.Final</version> <type>pom</type> <scope>provided</scope> </dependency>
Se prendiamo uno dei quickstart disponibili, basati sul web stack, vediamo che riportano:
<dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-web-6.0</artifactId> <version>2.0.0.Final</version> <type>pom</type> <scope>provided</scope> </dependency>
A questo punto basta sostituirlo con l'xml riportato sopra e prendere spunto dal pom di uno dei quickstart per avere un progetto maven pronto per essere utilizzato. Riporto sotto un pom generalizzato con le dipendenze corrette per lo stack full:
<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.mygroup</groupId> <artifactId>myArtifact</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>projectName</name> <inceptionYear>2011</inceptionYear> <description> project description </description> <profiles> <profile> <id>profilo1</id> <properties> <targetenv>profilo1</targetenv> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>profilo2</id> <properties> <targetenv>profilo2</targetenv> </properties> </profile> <profile> <id>profilo3</id> <properties> <targetenv>profilo3</targetenv> </properties> </profile> </profiles> <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-6.0</artifactId> <version>2.0.0.Final</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- Import the CDI API, we use provided scope as the API is included in JBoss AS 7 --> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <scope>provided</scope> </dependency> <!-- Import the Common Annotations API (JSR-250), we use provided scope as the API is included in JBoss AS 7 --> <dependency> <groupId>org.jboss.spec.javax.annotation</groupId> <artifactId>jboss-annotations-api_1.1_spec</artifactId> <scope>provided</scope> </dependency> <!-- Import the Servlet API, we use provided scope as the API is included in JBoss AS 7 --> <dependency> <groupId>org.jboss.spec.javax.servlet</groupId> <artifactId>jboss-servlet-api_3.0_spec</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-jpamodelgen</artifactId> <version>1.1.1.Final</version> <scope>provided</scope> <!-- Excluded because it's provided by the Java EE 6 dependencies --> <exclusions> <exclusion> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> </exclusion> </exclusions> </dependency> <!-- Seam Solder provides convenient, portable CDI extensions such as an injectable logger --> <dependency> <groupId>org.jboss.seam.solder</groupId> <artifactId>seam-solder</artifactId> <version>3.0.0.Final</version> </dependency> <!-- JSR-303 (Bean Validation) Implementation --> <!-- Provides portable constraints such as @Email --> <!-- Hibernate Validator is shipped in JBoss AS 7 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.1.0.Final</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> </exclusions> </dependency> <!-- Include the JBoss' Java EE 6 APIs --> <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) of artifacts. We use this here so that we always get the correct versions of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can read this as the JBoss stack of the Java EE 6 Web Profile APIs), and we use version 2.0.0.Beta1 which is the latest release of the stack. You can actually use this stack with any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! --> <dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-6.0</artifactId> <version>2.0.0.Final</version> <type>pom</type> <scope>provided</scope> </dependency> </dependencies> <build> <defaultGoal>install</defaultGoal> <finalName>artifactFinalName</finalName> <filters> <filter>src/main/filters/${targetenv}.filter.properties</filter> </filters> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <versionRange>1.0-alpha-2</versionRange> <goals> <goal>read-project-properties</goal> </goals> </pluginExecutionFilter> <action> <execute /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <warSourceExcludes>WEB-INF/lib/*.jar</warSourceExcludes> <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors> <webResources> <resource> <directory>${basedir}/src/main/webapp</directory> <filtering>true</filtering> <includes> <include>**/*.html</include> <include>**/*.jsp</include> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </webResources> </configuration> </plugin> <plugin> <groupId>com.google.code.maven-license-plugin</groupId> <artifactId>maven-license-plugin</artifactId> <version>1.4.0</version> <configuration> <header>../src/etc/license.txt</header> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.1</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.2</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <version>1.0-alpha-2</version> <configuration> <files> <file>${basedir}/src/main/filters/${targetenv}.filter.properties</file> </files> </configuration> <executions> <execution> <phase>process-resources</phase> <goals> <goal>read-project-properties</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.0-beta-9</version> <configuration> <goals>clean compile package install</goals> <autoVersionSubmodules>true</autoVersionSubmodules> <tagBase></tagBase> <releaseProfiles>pro</releaseProfiles> </configuration> </plugin> <!-- JBoss AS plugin to deploy war --> <plugin> <groupId>org.jboss.as.plugins</groupId> <artifactId>jboss-as-maven-plugin</artifactId> <version>7.0.0.Final</version> </plugin> </plugins> </build> <scm> <connection>myconnection</connection> <developerConnection>mydevconnection</developerConnection> <url>myurl</url> </scm> </project>
Questo pom comprende anche dei filtri. Per utilizzarli bisogna creare un file per ogni profilo in src/main/filters. Il file dovrà essere del tipo nomeprofilo.filter.properties e mettervi all'interno tutte le proprietà che vanno filtrate come chiave=valore, che vanno riferite all'interno dei files di configurazione come ${chiave}. Per attivare i vari profili nella build di maven basta aggiungere l'opzione -P nomeprofilo.
Nessun commento:
Posta un commento