Posts Tagged ‘Application Server’

After setting up a data source in your AppServer, e.g. for WebLogic Server, you want to use it in your application with JPA.

Basically there are three ways to connect to a db with JPA:

  • JDBC data source with JTA transactions (not supported by a Servlet-Container like Tomcat)
  • JDBC data source with self-managed transactions, i.e. transaction-type=”RESOURCE_LOCAL”
  • direct JDBC connection

The first and second are well discussed in the www. So we give an example on the second with provider Hibernate:

<persistence-unit name="PU_ResourceLocal_WithDS" transaction-type="RESOURCE_LOCAL">

  <!-- the JNDI name as specified in your AppServer -->

    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    <property name="hibernate.max_fetch_depth" value="5" />

For Tomcat 6 and EclipseLink this is well explained in

, , , , , ,


If you use JPA with Hibernate, CDI with Weld, then the default Tomcat PermGen (permanent Generation) size is soon becoming too small – already for dev purposes without user load…

E.g., if you have 2GB of RAM, reserve 1GB for your OS, you could give a dedicated Tomcat server about 1GB:

If you’re using the startup.bat, append following line in catalina.bat in front of JAVA_OPTS:
-Xms1024m -Xmx1024m -XX:MaxPermSize=128m

set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\" -Xms1024m -Xmx1024m -XX:MaxPermSize=128m

You also could add a new environment variable called JAVA_OPTS with value -Xms1024m -Xmx1024m -XX:MaxPermSize=128m

I also was in the situation of a Win XP machine with 512MB of RAM, where I set -Xms256m -Xmx256m -XX:MaxPermSize=64m. There could not run any more processes without starting to page… There also ran a HSQLDB, and sometimes I opened Eclipse together with Firefox :-)

, ,


For the use of JSF you only need a servlet container (no full application server).

JSF 1.2, 2.0: Servlet 2.5 / JSP 2.1 container

JSF 1.2 and JSF 2.0 depend only on Servlet 2.5 / JSP 2.1 containers. Note that EL 2.1 is a component of the JSP 2.1 Specification. This is the case in JEE 5 AppServers:

  • Tomcat 6
  • Glassfish 2
  • JBoss AS 5
  • Oracle WebLogic 11g
  • IBM WebSphere 7, etc.

E.g. So you can use JSF 2.0 in Tomcat 6, but not the features of EL 2.2, like call JSF action method with arguments. To tune Tomcat 6 towards Java EE 6 see here.

JSF 2.1, 2.2: Servlet 3.0 / JSP 2.2 container

JSF 2.1 and JSF 2.2 depend on Servlet 3.0 / JSP 2.2 containers. Note that EL 2.2 is a component of the JSP 2.2 Specification. This is the case in JEE 6 AppServers:

  • Tomcat 7
  • Glassfish 3
  • JBoss AS 6
  • Oracle WebLogic 12g
  • IBM WebSphere 8
  • or newer versions

For an overview of JEE 6 compatible servers:
What’s new in JSF 2.1? It’s mainly a maintenance release: (German)

, , , , , , , , , , , ,


After installing the database, I’m getting the WebLogic Server 11gR1 (10.3.3). You have to accept again the same “OTN License Agreement”.

Installation of WLS

Download and unzip

1. At the download page of Oracle WebLogic Server  you can choose versions for different platforms (32/64 bit). Although I would prefer the 64 bit version I’m sticking to the 32 bit version, due to the easy Windows Installer (double-click exe, and follow a wizard…) – I don’t want to invest too much time in the installation.
I choose the full package with Oracle Coherence and Oracle Enterprise Pack for Eclipse, although I won’t need Coherence but want to check out the OEPE (there’s also a zip with AppServer only, but the readme reveals no exe-installation with manual configuration – unfortunately WLS installation isn’t as easy as JBoss, Glassfish: unzip, done). So download

  • wls1033_oepe111150_win32.exe (about 0,9 GB)

Optional download: Documentation package, if you want offline all the WLS 11gR1 oracle docs in html and pdf version.


2. Double-click wls1033_oepe111150_win32.exe, and wait for preparation of installation, about 5 min.

3. Follow the wizard:

  • Create a “Middleware Home Directory”, I choose the suggested one C:\Oracle\Middleware (in C:\Oracle also lies the db)
  • choose “Typical” installation (vs. “Custom”)
  • accept the suggested installation directories:
  • WebLogic Server: C:\Oracle\Middleware\wlserver_10.3
  • Oracle Coherence: C:\Oracle\Middleware\coherence_3.5
  • Oracle Enterprise Pack for Eclipse: C:\Oracle\Middleware\oepe_11gR1PS2
  • Create shortcuts in start menu for “all users” as recommended
  • Check installation summary, click “Next” to start the actual installation, wait about 20 min., time for a coffee :-)

4. Check “Run Quickstart” and press “Done” to create and configure a WLS domain:

  • in Quickstart, select “Getting started with WebLogic Server 10.3.3″
  • next select “Create a new WebLogic domain”
  • Select to “Generate a domain configured automatically to support the following products:” and check JAX-RPC- and JAX-WS extensions
  • enter domain name and location: I choose “mh_domain” and C:\Oracle\Middleware\user_projects\domains
  • configure the administrator user name and password: I choose “admin” and some easy to remember pwd (it has to be longer than 8 chars)
  • choose “Development Mode” and Sun SDK for getting the user/pwd out if and poll for apps to deploy (auto-deploy)
  • check no further configurations, inspect the summary and click “Next”, installation complete!


Starting and Stopping WLS


Visit the admin server http://localhost:7001/console and log in as the admin as specified before.

, , ,


This should work theoretically with every Servlet 2.5 / JSP 2.1 container, but tested with Tomcat 6 only…


If your customer forces you to run your WebApps in an old Servlet 2.5 / JSP 2.1 container ;-) , but you want to kick off using new JEE 6 stuff, then heres how you get started:

JSF 2.0

JSF 2.0 just needs Servlet 2.5 / JSP 2.1 container (JSF 2.1+ needs alredy Servlet 3.0). Download the reference implementation Mojarra or Apache MyFaces and put the two jars into the WEB-INF/lib:


EL 2.2 or JBoss EL

Have you ever wished to pass an argument to your JSF-actions in your view? Like

<h:commandButton value="edit" action="#{bean.edit(user)}" />

with backing bean method

public void edit(User user) {...}

JBoss EL 2.0.1.GA

This is possible with JBoss EL implementation, see Add to your pom:


and to your web.xml


EL 2.2

Or use EL 2.2, which is a component of the JSP 2.2 spec. You need to put the two EL JARs into the WEB-INF/lib: el-api-2.2.0.jar, el-impl-2.2.0.jar. Add to your web.xml:


Note: If you also use CDI with Weld, this ends up in an exception:
LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;"
One way out is to replace in the apache-tomcat/lib the el-api.jar with el-api-2.2.jar and el-impl-2.2.jar and put in your pom.xml:


If you cannot change the server itself then stick to JBoss EL.


If you want to use CDI managed beans (@Named) instead of JSF managed beans (@ManagedBean) in a plain Servlet container, then you can use the reference implementation Weld:,
CDI is the new JEE 6-standardized way for managing beans: it’s more robust, and the same as in an EJB context. Furthermore you can use a conversation scope. I still like the JSF view scope, so maybe drop JSF management totally, or mix it.
For setup refer to There it is explained:

Just drop into WEB-INF/lib


and add to your web.xml:

  <description>Object factory for the CDI Bean Manager</description>

Bean Validation

“Declare once, validate anywhere!” is the advertisement for Bean validation: Don’t put your validation in the views, DAOs/DTOs, etc., but put your validation only at one place:
your beans (although in real life in the database remain ranges, constraints, etc., so some redundancy remains…). If you have different pages with input data to the same data, then this is a big advantage for maintenance: change at one place.

public class Bean {
private String name;

Again use the RI from Hibernate and drop it to WEB-INF/lib:

all JARs in the lib directory of the downloaded zip file.

Note: JSF 2.0 directly supports Bean Validation. In JSF 1.2 you could use RichFaces 3.3.3.

JPA 2.0

Some drawbacks without a real AppServer is that

  • manage your transactions by yourself with EntityTransaction (no JTA transactions).
  • direct resource handling, i.e. use the persistence factory EntityManagerFactory to obtain an EnitityManager (no injections possible, because of the lack of EJBs), also don’t forget to close your EntityManager…

Get a JPA provider, e.g. Hibernate and EclipseLink. For EclipseLink, see For Hibernate just get the zip from and follow the good documentation.

You need to setup your persistence.xml and make some provider and database specific configurations.

, , , , , , , , , , , , , ,