Migration Cheat Cheet for Java EE 5 to Java EE 6 Shane K Johnson

treeexcellentΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 5 μήνες)

78 εμφανίσεις

Migration Cheat Cheet for Java EE 5 to Java EE 6
Shane K Johnson
Java EE 6
EJB via CDI
1.
Create a qualifier (annotation) for the EJB.
@Qualifier
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
public @interface MyBeanLocal {
}
2.
Create a new class to define the EJB as a resource using @EJB and to provide a producer method with the

qualifier.
@EJB
MyBeanLocal myBean; // MyBeanLocal (EJB Local Interface) extends MyBean (POJO Interface)
@Produces
@MyBeanLocal
public MyBean getMyBean() {
return myBean;
}
3.
Use @Inject to inject the EJB as a resource into a separate resource.
@Inject
@MyBeanLocal
MyBean myBean;
JAX-RS via CDI
1.
Delete the RESTEasy servlet configuration from the web.xml file, or delete the web.xml file itself.
2.
Create the XML descriptor file (beans.xml) in the META-INF | WEB-INF directory to enable CDI.
<?xml version="1.0"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd" />
3.
Create a JAX-RS Application subclass with @ApplicationPath and @ApplicationScoped annotations.
@ApplicationPath("/myapplication")
@ApplicationScoped
public class MyApplication
extends
Application
{
}
http://howtojboss.com/2013/01/10/migration-cheat-sheet-and-checklist-for-java-ee5-to-java-ee6/
1
/
6
Migration Cheat Cheet for Java EE 5 to Java EE 6
Shane K Johnson
Java EE 6
JPA
1.
If the GenerationType.AUTO strategy defaults to the GenerationType.SEQUENCE strategy, replace it with the

GenerationType.SEQUENCE strategy and supplement it with the @SequenceGenerator annotation.
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "my_sequence")
@SequenceGenerator(name = "my_sequence", sequenceName = "my_sequence")
@GeneratedValue(strategy = GenerationType.AUTO)
2.
If second level caching is configured, replace @Cache (Hibernate) annotations with @Cacheable (JPA)

annotations.
@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
3.
If second level caching is configured, update the configuration properties in the persistence.xml file.
<properties>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />

<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>

<property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>

<property name="hibernate.cache.region.jbc2.cfg.query" value="local-query"/>
</properties>
http://howtojboss.com/2013/01/10/migration-cheat-sheet-and-checklist-for-java-ee5-to-java-ee6/
2
/
6
Migration Cheat Cheet for Java EE 5 to Java EE 6
Shane K Johnson
JBoss EAP 6
Arquillian
1.
Delete the auth.conf file.
2.
Delete the jndi.properties file.
3.
Update the Arquillian configuration in the arquillian.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="jboss" default="true">
<configuration>

<property name="managementAddress">localhost</property>

<property name="managementPort">9999</property>

<property name="contextFactory">org.jboss.security.jndi.LoginInitialContextFactory</property>
</configuration>
</container>
</arquillian>
EJB Client
1.
Update the properties for the initial context.
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
2.
Update the JNDI name.
ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>
<appName>/<beanName>/remote
3.
Create the jboss-ejb-client.properties file.
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=4447
http://howtojboss.com/2013/01/10/migration-cheat-sheet-and-checklist-for-java-ee5-to-java-ee6/
3
/
6
Migration Cheat Cheet for Java EE 5 to Java EE 6
Shane K Johnson
JBoss EAP 6
JMS
1.
Move the JMS configuration file to the META-INF directory and rename it (*-service.xml to *-jms.xml).
2.
Update the JMS configuration file.
<?xml version="1.0" encoding="UTF-8"?>
<messaging-deployment xmlns="urn:jboss:messaging-deployment:1.0">
<hornetq-server>
<jms-destinations>
<jms-queue name="MyQueue">
<entry name="/queue/MyQueue" />
</jms-queue>
</jms-destinations>
</hornetq-server>
</messaging-deployment>
JNDI
1.
Update the JNDI names of JMS resources.
@Resource(mappedName = "
java:/
queue/MyQueue")
@Resource(mappedName = "queue/MyQueue"
)
Queue limitOrderDest;
@Resource(mappedName = "
java:/
ConnectionFactory")
@Resource(mappedName = "java:/ConnectionFactory")
QueueConnectionFactory connectionFactory;
http://howtojboss.com/2013/01/10/migration-cheat-sheet-and-checklist-for-java-ee5-to-java-ee6/
4
/
6
Migration Cheat Cheet for Java EE 5 to Java EE 6
Shane K Johnson
Maven
Java EE 6
1.
Add the JBoss Java EE 6 API dependency (BOM).
<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.jboss.spec</groupId>

<artifactId>jboss-javaee-6.0</artifactId>

<version>3.0.1.Final</version>

<scope>import</scope>

<type>pom</type>

</dependency>

</dependencies>
</dependencyManagement>
2.
Add the CDI API dependency.
<dependency>

<groupId>javax.enterprise</groupId>

<artifactId>cdi-api</artifactId>

<scope>provided</scope>
</dependency>
3.
Replace the EJB API dependency.
<dependency>

<groupId>org.jboss.spec.javax.ejb</groupId>

<artifactId>jboss-ejb-api_3.1_spec</artifactId>

<scope>provided</scope>
</dependency>
4.
If the RESTEasy dependency was
only
required for

the JAX-RS implementation, remove it and its

dependencies.
5.
If the RESTEasy dependency was required for the

client framework, update it.
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>

<version>2.3.2.Final</version>
</dependency>
6.
Replace the JAX-RS API dependency.
<dependency>

<groupId>org.jboss.spec.javax.ws.rs</groupId>

<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>

<scope>provided</scope>
</dependency>
7.
Replace the JMS API dependency.
<dependency>

<groupId>org.jboss.spec.javax.jms</groupId>

<artifactId>jboss-jms-api_1.1_spec</artifactId>

<scope>provided</scope>
</dependency>
8.
If the Hibernate Annotations dependency was
only

required for the @Cache annotation, remove it.
9.
Replace the JPA API dependency.
<dependency>

<groupId>org.hibernate.javax.persistence</groupId>

<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
10.
Configure the Maven WAR plugin.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>

<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
11.
Update the Maven EAR plugin configuration.
<configuration>

<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
http://howtojboss.com/2013/01/10/migration-cheat-sheet-and-checklist-for-java-ee5-to-java-ee6/
5
/
6
Migration Cheat Cheet for Java EE 5 to Java EE 6
Shane K Johnson
Maven
JBoss EAP 6
1.
Update the Arquillian dependency (BOM).
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>

<version>1.0.0.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
2.
Replace the Arquillian JBoss AS, the JBoss AS

Client, and the JBoss AS Profile Service Client

dependencies with the JBoss AS Arquillian

dependency.
<dependency>

<groupId>org.jboss.as</groupId>

<artifactId>jboss-as-arquillian-container-remote</artifactId>

<version>7.1.1.Final</version>
</dependency>
3.
Remove the JBoss AS Client dependency.
4.
Add the JBoss AS EJB Client dependency (BOM).
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.1.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
5.
Add the JBoss AS EJB Client dependencies.
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.sasl</groupId>
<artifactId>jboss-sasl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>

<groupId>org.jboss.spec.javax.ejb</groupId>

<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>

<groupId>org.jboss.spec.javax.transaction</groupId>

<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<scope>runtime</scope>
</dependency>
6.
Replace the Maven Cargo plugin with
the JBoss AS (7) plugin.
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.1.Final</version>
<configuration>
<username>admin</username>
<password>password</password>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>undeploy</goal>
</goals>
</execution>
</executions>
</plugin>
http://howtojboss.com/2013/01/10/migration-cheat-sheet-and-checklist-for-java-ee5-to-java-ee6/
6
/
6