- Developer Tools
Jérémy Aubert, August 1, 2012
One of the new features of Stackato 2.0 is the support of JEE applications.
Java Enterprise Edition is the enterprise side of Java. This platform provides an API and runtime environment for developing and running enterprise software.
There are a number of servers supporting JEE applications (like GlassFish and Geronimo) but in our case, we decided the use the new Apache baby: TomEE. It is light, fast, and reliable!
So what is TomEE?
Apache TomEE is the Java Enterprise Edition of Apache Tomcat. It's a Java EE 6 Web Profile server, and it supports all the JEE features (J2EE, JEE5, JEE6).
Deploying a JEE application to Stackato
You can deploy your application just like you did with previous versions of Stackato. You build your WAR file and push it to Stackato. The Stackato Java EE framework will be detected if there is a persistence.xml file located in src/main/resources/META-INF/.
There is however, something you need to know about packaging your application.
Your JEE application (EJBs and Servlets) has to be contained in one WAR file as one application. This is different from the J2EE and JEE5 packaging, as there is no EAR file anymore. There is no separation between servlets and EJBs. They can share all third-party libraries. They can see each other.
This packaging approch is truly JEE6 certified.
Push to Stackato
Again, the basic idea is the same as previous versions of Stackato. Build you application, then push it to Stackato. It's still that easy!
The Numberguess example in the Stackato-Apps samples on Github show how this is done.
To run this application:
git clone https://github.com/Stackato-Apps/Numberguess cd Numberguess mvn clean package (or ant clean package) stackato push -n
We have also added a cool feature in Stackato 2.0 for Java EE applications which makes it much easier to use database services!
How to use database services
First create your database service in Stackato with a specific name. For our example, let's say this is a mysql service which is called 'mysql-service'.
For each service you create, Stackato creates a resource in the TomEE configuration:
<Resource id="mysql-service" type="DataSource"> JdbcDriver com.mysql.jdbc.Driver JdbcUrl jdbc:mysql://url:port/database UserName user Password password JtaManaged true </Resource>
Next, create your persistence.xml file in src/main/resources/META-INF/ and refer to this resource:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="my-unit" > <jta-datasource>mysql-service</jta-datasource> </persistence-unit> </persistence>
NOTE: If there is only one service, there is no need to write the 'jta-datasource' tag. As there is only one service, JEE knows it's this one you want to use.
Finally, in you java code, you create your EntityManager and refer to the persistence-unit you want to use:
@PersistenceContext(unitName="my-unit") private EntityManager em;
NOTE: If there is only one persistence-unit, there is no need to write the 'unitName'.
Trackback URL for this post:
Category: stackatoSHARE THIS: