Friday, July 31, 2009

Spring 3.0.0.M3 on Google Appengine with JPA


I am working on a private project these days. It should give myfear.com and myfear.de a new meaning. Therefore I am trying out Google's Appengine.
Beeing forced to more or less full blown JEE5 in my dayly work, I wanted to try out something new. Having worked with older Spring versions some time ago, I feelt it was time to give this another shot. And so I ended up, trying Spring's newest milestone release on the GAE.

At the end of the day, I solved many problems on the road and everything worked fine. Here is a brief summary of what I had to change/find out:

1) GAE does not support full blown JEE. Therefore you have to be very sensible for using the right combination of technologies. If you try to use spring completely you will fail. The following list of jar files did the job for me:
antlr-3.0.1.jar
aopalliance-1.0.jar
asm-2.1.jar
asm-commons-2.1.jar
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
commons-lang.jar
commons-logging.jar
org.springframework.aop-3.0.0.M3.jar
org.springframework.asm-3.0.0.M3.jar
org.springframework.aspects-3.0.0.M3.jar
org.springframework.beans-3.0.0.M3.jar
org.springframework.context-3.0.0.M3.jar
org.springframework.core-3.0.0.M3.jar
org.springframework.expression-3.0.0.M3.jar
org.springframework.jdbc-3.0.0.M3.jar
org.springframework.orm-3.0.0.M3.jar
org.springframework.transaction-3.0.0.M3.jar
org.springframework.web-3.0.0.M3.jar
org.springframework.web.servlet-3.0.0.M3.jar

2) Setting up the persistance.xml is straight forward but remember to rename the persistance-unit in jdoconfig.xml. Both should have different names!

<persistence-unit name="transactions-optional">
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true" />
<property name="datanucleus.NontransactionalWrite" value="true" />
<property name="datanucleus.ConnectionURL" value="appengine" />
</properties>
</persistence-unit>

3) Defining the entity manager in dispatcher-servlet.xml

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"
lazy-init="true">
<property name="persistenceUnitName" value="transactions-optional" />
</bean>
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

Don't forget to add the following two, if you want to use JPA @Annotations in your Entities and Spring @Annotations in your DAOs and Services.

<tx:annotation-driven />

<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />


4) Injecting the EntityManager in your @Repository Daos:


private EntityManager entityManager;

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}


5) If you try to use the injected entityManager without any transaction, then you would most likely get an NucleusUserException: Object Manager has been closed. You can prevent this, using @Service and @Transactional in your service layer.

6)Nearly the same could happen, if you do not call queryResult.size() on your query.getResultList(). The error was reported several times. There seems to exist only this "workaround".

7) Using EL Expressions in your JSP forces you to use a little addon to the jsp page definition:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" %>

8) If you would like to use the <fmt:formatDate jstl tags, you have to enable session management in your appengine-web.xml. <sessions-enabled>true</sessions-enabled>

9) I came across several problems using a JRE with eclipse and GAE local server. You should always use a JDK!

All for now ... more to come :)

Friday, July 24, 2009

Software engineering is an idea whose time has come and gone


Have you read the recent IEEE-Article from Tom DeMarco (PDF)?


My early metrics book, Controlling
Software Projects: Management,
Measurement, and
Estimation (Prentice Hall/Yourdon
Press, 1982), played a role
in the way many budding software
engineers quantified work
and planned their projects. In
my reflective mood, I’m wondering,
was its advice correct at the
time, is it still relevant, and do I
still believe that metrics are a must for any successful
software development effort? My answers
are no, no, and no.

[...]

I'm gradually coming to the conclusion that software engineering is an idea whose time has come and gone.

[...]

Software development is and always will be somewhat experimental. The actual software construction isn't necessarily experimental, but its conception is. And this is where our focus ought to be. It's where our focus always ought to have been.
(Tom DeMarco)


Dont forget to read the interpretation from Jeff Atwood.


What DeMarco seems to be saying -- and, at least, what I am definitely saying -- is that control is ultimately illusory on software development projects. If you want to move your project forward, the only reliable way to do that is to cultivate a deep sense of software craftsmanship and professionalism around it.
(Jeff Atwood)


What nearly anybody seems to know. This articel is not too new. Find a german version published in the ObjektSpektrum 08/2006 here.

What I love most in this discussion is a quote from Tom DeMarco:


“Software development is and always will be somewhat experimental.” (DeMarco)

last days of edocs.bea.com


Starting August 31, 2009, edocs.bea.com will no longer be maintained.
At that time, edocs documentation will be available from the Oracle Technology Network only.

The new direct link to the WLS 10gR3 is now:
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/sitemap.html

Using Maven Dependency Projects


Maven is number one in managing dependencies. This could get even simpler, if you use plugins for your favourite ide (e.g. m2eclipse).
Anyway, dependency management is the most challinging part in maven projects. If you have a growing project, you should sit back and think about the project structure and the needed dependencies a bit.
Best practice building jee applications for me is to use so called "dependency projects". If you have your web project you simply add another project called web-deps of type pom and link a dependency to it from your web project. Now you have a single place, where you can manage all your dependencies for your web project.



There are several advantages of this approach:
* One central place to manage all dependencies of your web/ejb projects. You can have some web-tools projects that depend on the deps. This helps preventing circles.
* Assign one responsible person in your project managing the deps.
* Easier change container dependencies. By only adding new deps projects and not breaking the actuall build. This gives you the option to have one deps project per container for example (e.g. web-deps-wls, web-deps-was).



Follow the other parts of this series:



Download the complete Quickstart Maven JEE5 Project.

Wednesday, July 22, 2009

Adding additional Source Folders to Maven Project


Most projects today have at least one part, that is generated in anyway. This is not too easy to integrate with maven. Mostly the generator's build relys on ant. Therefore it's always a discussion, where to place the build and how to trigger it. The most easiest way is to have a separate java eclipse project that builds with ant and copying the generated ressources to a /gen/ folder within your maven project. Beside the disadvantage, that you have a possible stale version of the generated sources checked in with your repository there are also some advantages, too.
Even if the majority of your team memvers do not have the generator project setup, they can still develop. Beside this, you skip the mostly tricky part of shipping a bunch of additional eclipse plugins to the rest of the team and you can keep the model itself under control of a selected group of persons. Anyway, if you have such a setup, it is no good idea to copy the generated sources to your /main/java folder. It should be obvious to the developers, that there are generated sources in the project. A practical workaround for this is to have different java src folders in your projects. This could be a /main/gen folder for example. In order to tell maven about it, you need to add additional resources to your projects pom-file.
Resource folder are ment for resources and not for java files. Therefore this is quite a bit like a workaround. But it works :)
The following snippet assumes three src folders in your project.

<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include> **/*.java </include>
<include> **/*.properties </include>
<include> **/*.xml </include>
</includes>
</resource>
<resource>
<directory>src/main/gen</directory>
<includes>
<include> **/*.java </include>
<include> **/*.properties </include>
<include> **/*.xml </include>
</includes>
</resource>
<resource>
<directory>src/main/test</directory>
<includes>
<include> **/*.java </include>
<include> **/*.properties </include>
<include> **/*.xml </include>
</includes>
</resource>
</resources>

Tuesday, July 21, 2009

Generating Static WAR Content Archive with Maven


You may have seen my simple JEE5 maven project setup already. I am trying to add more and more features during the next few weeks that satisfy the needs of enterprise software development.

First add-on is the possibility to have a separate static-web.zip generated, which contains all relevant content, that should be deployed to a separate webserver.

All you have to do is to add the following to your war/pom.xml

<plugin>
<!-- assamble static content -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/static.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

Next step is to add a new folder in the web project (src\main\assembly) and create the needed assembly file (static.xml)

<assembly>
<id>static</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/webapp</directory>
<includes>
<include>**/*.html</include>
<include>**/*.htm</include>
<include>**/*.jpg</include>
<include>**/*.gif</include>
<include>**/*.css</include>
<include>**/*.js</include>
</includes>
<excludes>
<exclude>WEB-INF/*</exclude>
</excludes>
<outputDirectory>/static</outputDirectory>
</fileSet>
</fileSets>
</assembly>


If you now run maven clean install than you get a new static-web.zip file generated, which contains all the defined files and folders.

Quickstart Maven JEE5 Project


I had to start several JEE5 projects recently and always needed to setup a new maven project structure over and over again. Therefore I decided to build a basic maven project setup for a default JEE5 application containing:
- one EAR project
- one EJB project
- one WAR project

You can download the project setup and give it a try. All projects have the base setup from the JEE5 facets of the related maven plugins. Therefore: Don't expect any magic behind this. The only intention of this was to have a quickstart and don't waste any time on creating the same four poms and folder structures over and over again.

Have a look at the general project structure:

Friday, July 17, 2009

Sun's Stockholders approve Acquisition


Sun's stockholders approved the company's sale to Oracle for $9.50 a share Thursday.
In an special meeting held at Santa Clara, CA, 62% of Sun's stockholders voted for the acquisition. As a result of this Sun's stock will be taken from the stock market as of Friday.

The deal still needs U.S. and European regulatory sanctions.
If, as Oracle's lawyers said to expect, the deal closes by the end of August, it would be quicker than is usual after a second request for information by the Justice Department.
The agency is reportedly asking questions about Java.

Thursday, July 16, 2009

JPA implementation patterns


Vincent Partington has written a series of blog posts about the JPA implementation patterns he discovered while writing JPA code.

Basic patterns

* Data Access Objects
* Saving (detached) entities
* Retrieving entities
* Removing entities
* Service Facades and Data Transfers Objects

Advanced patterns

* Bidirectional assocations
* Lazy loading
* Bidirectional associations vs. lazy loading
* Using UUIDs as primary keys
* Field access vs. property access
* Mapping inheritance hierarchies
* Testing

Wednesday, July 15, 2009

JSF 2's new features


With version 2.0, Java™Server Faces (JSF) makes it easy to implement robust, Ajaxified Web applications. The recent article series by JSF 2.0 Expert Group member David Geary showing you how to take advantage of the new features in JSF 2.

Streamline Web application development
The first part is about: streamlined development with JSF 2 by replacing XML configuration with annotations and convention, simplifyed navigation, and easily resource access. And you'll see how to use Groovy in your JSF applications.
read it on developerworks!

Templating and composite components
JSF 2 lets you implement user interfaces that are easy to modify and extend with two powerful features: templating and composite components. The second article in this series on JSF 2's new features shows you how your Web applications can best take advantage of templating and composite components.
read it on developerworks!

Event handling, JavaScript, and Ajax
Third and last part is about the framework's new event model and built-in support for Ajax. This is how to make your reusable components all the more powerful.
read it on developerworks!

Author, speaker, and consultant David Geary is the president of Clarity Training, Inc., where he teaches developers to implement Web applications using JSF and Google Web Toolkit (GWT). He was on the JSTL 1.0 and JSF 1.0/2.0 Expert Groups, co-authored Sun's Web Developer Certification Exam, and has contributed to open source projects, including Apache Struts and Apache Shale. David's Graphic Java Swing was one of the best-selling Java books of all time, and Core JSF (co-written with Cay Horstman), is the best-selling JSF book. David speaks regularly at conferences and user groups. He has been a regular on the NFJS tour since 2003, has taught courses at Java University, and was twice voted a JavaOne rock star.

Tuesday, July 14, 2009

Gmail4J - accessing Gmail services from Java


Gmail4J is a simple, object oriented library for accessing Gmail services from Java. The actual build version 0.3 is available under a Apache License 2.0 from code.google.com.

You can use it with maven (Java.net Repository):

<dependency>
<groupId>com.googlecode</groupId>
<artifactId>gmail4j</artifactId>
<version>0.3</version>
</dependency>


Some example code? Get unread Messages from your account (through proxy):

GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
connection.setProxy("proxy.example.com", 8080);
client.setConnection(connection);
final List messages = client.getUnreadMessages();
for (GmailMessage message : messages) {
System.out.println(message);
}


Looks like this:

Building a modern Java app with Eclipse, Maven, OSGi, and Spring DM


Kyle Smith (VMware) posted a series of blogposts where he talks about using Eclipse, Maven, OSGi, and Spring DM in a real life project.

First part
Second part

Monday, July 13, 2009

JBoss Tools 3.1 M2 released


The JBoss Tools 3.1 M2 Milestone was released on the 10th of july.



New Features

  • Support for Maven

  • Archived Update Site

  • XHTML Validation

  • Conditional rendering in Visual Page Editor

  • Improved incremental validation

  • Smooks

  • jBPM 4



More details can be found on the related blogpost.

Sunday, July 12, 2009

Time is changing


And so is the free space, if you have a toddler at home :) Therefore I am giving away a nice toy. My Cobalt Qube2.

If you like, you can take part in the ebay auction.
I will buy some extra toys for my daughter from the gathered money :)

Friday, July 10, 2009

Using Hibernate 3.x in Weblogic Server 10gR3 and 11g


If you ever tried using a different O/R mapper than the ones provided by Oracle, you may have come across several issues. The most common one is a problem with the ANTLR packages. Hibernate3 uses ANTLR for the new query parser. Oracle Weblogic includes a version of ANTLR in the system classpath which will be loaded before any application libraries. If you are using Hibernate in your Webapplication you will need to package the hibernate.jar and all dependencies within you WEB-INF/lib directory. The parent ear file should have an additional weblogic-application.xml descriptor to which the configuration for the FilteringClassLoader is added.


<prefer-application-packages>
<package-name>antlr.*</package-name>
</prefer-application-packages>


If you use Hibernate as JPA provider and package your Entities in the ejb.jar files, you should only add the jars to the APP-INF/lib directory of the ear file. This works without any further problems.

Don't try changing or removing the distributed modules (BEA_HOME/modules)
com.bea.core.antlr.runtime_2.7.7.jar or
com.bea.core.antlr_2.7.7.jar
You will get in deeper trouble (e.g. admin console not completely working).

Oracle Application Grid Podcasts


According the the Oracle ArchBeat Blog, the entire OTN Arch2Arch Podcast interview with Oracle’s Bill Dettelback is now available. In this interview Bill discusses Oracle Application Grid as an architectural concept, describes some of the similarities and differences between Application Grid and other architectural approaches, talks about the roles Weblogic Server, Coherence, Enterprise Manager, Tuxedo, and JRockit play within the Application Grid architecture, and then wraps it all up by talking about what it all means for architects.

Listen to Part 1: Application Grid: Under the Hood

Listen to Part 2: Application Grid: What’s in it for Architects

Basics: Debugging with Oracle Weblogic Server


Remote Debugging a JVM is quite simple at all. This is the same, if you are trying to debug an Oracle Webglogic Server instance.
Grep your favourite IDE and give it a try.

First thing to do, is to enable Debugging with Oracle Weblogic Server. Look out for the startWeblogic.cmd/sh in your Weblogic Server Domain and add the needed properties to the java options:


(Windows)
set JAVA_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n

(Unix/Linux)
JAVA_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n
export OPTIONS


The -XDebug parameter enables debugging. The -Xnoagent parameter disables the default sun.tools.debug debug agent. The -Xrunjdwp parameter loads the JPDA reference implementation of JDWP. Debugging is enabled on port 4000. The JDWP protocol is the protocol used to debug with a remote debugger.

After this, start the WebLogic Server by invoking the startWebLogic.cmd/sh script.

Next step is to deploy your application to the server. You can do this, however you like to. Use the Oracle Enterprise Pack for Eclipse or the autodeploy feature or even the weblogic administration console.

Now start your favourite IDE and look out for the debugging view. If you are using Eclipse, open the Debug configurations and choose "Remote Java Application" and press the "new Launch Configuration" button and enter the needed values.



Now we must start the remote debugger. Right click on the class you want to debug and choose "Debug As" and your server configuration. The only thing left to do is to set the needed breakpoints in your code.

Tuesday, July 7, 2009

JSF 2.0-BETA 1 on Oracle Weblogic 10gR3


As you probably may have heard: JSF2.0 is final now. Time to give the available distributions a shot. I was curious to find out, that the actual available builds of the RI are still in BETA. Therefore I had to try it with the 2.0.0 Beta1 (26 May 2009).

To deploy new JSF libraries to the Oracle Weblogic server, you have to provide a separate application library. This is after all quite simple, but you have to take some actions at all.
- grep a sample from %ORACLE_HOME%\wlserver_10.3\common\deployable-libraries
- extract the .war (e.g.jsf-1.2.war) and rename the folder appropriate (e.g. jsf-2.0.1)
- change the libraries in WEB-INF/lib (you need the jsf-api.jar, jsf-impl.jar and the jstl-1.2.jar)
- change the META-INF/MANIFEST.MF to reflect the appropriate version informations:
Specification-Version: 2.0
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: JSF Reference Implementation (Mojarra 2.0.0 BETA1)
Implementation-Version: 2.0.1
- add a WEB-INF/classes folder and add the com.bea.faces.WeblogicInjectionProvider.class class to it
- last part is to zip everything together again and have a jsf-2.0.1.war

Now you are able to deploy the new library to the WLS. Make shure to add the managed library to your applications weblogic.xml.

<wls:library-ref>
<wls:library-name>jsf</wls:library-name>
<wls:specification-version>2.0</wls:specification-version>
<wls:implementation-version>2.0.1</wls:implementation-version>
<wls:exact-match>false</wls:exact-match>
</wls:library-ref>

and try out some samples. I came across several issues:
- It seems as if neither the com.sun.faces.taglib.jsf_core.BeanValidatorTag nor the com.sun.faces.taglib.jsf_core.RequiredValidatorTag are part of the distribution at the moment. Trying to start the samples app, leads to a class not found error. Only fix for now is to remove the Tags from the jsf_core.tld.
- Not all new @Annotations are processed with the WeblogicInjectionProvider for now. Therefore, even the simplest examples do not work as they should with this version.

Let's see, what happens with the final release, and how we could deploy this to the WLS :)

[UPDATE: 14.07.09]
Even the latest Oracle Fusion Middleware and within it the Oracle Weblogic 10.3.1.0 still only supports JSF 1.2.9.0. At the moment it is simply not possible to run JSF 2.0 on top of Weblogic Server.

Friday, July 3, 2009

Oracle Fusion Middleware 11g Launch


Yesterday I attended the Oracle Fusion Middleware 11g Launch in Munich. It was a small but very interesting event at all. Alex Andrianopoulos (Vice President, Oracle Fusion Middleware Product Marketing) and John Aisien (Vice President of Product Management,
Oracle Fusion Middleware, EMEA Oracle Corporation) gave a longer and more detailed overview about the new features of OFM 11g. After the break their track was followed by a couple of more deeper presentation about special topics.



What was most interesting at all from a weblogic point of view?

  • Within 11g all bea products are finaly integrated into the whole middleware stack.

  • The Weblogic Server is now available as 10.3.1.0 - a minor relase at all

  • You now have forms and reports integration in WLS

  • JRockit is available as jrockit_160_05_R27.6.2-20



You can download the new 11g release from the oracle technology network (otn). The basic weblogic server download now comes with the latest Oracle Enterprise Pack for Eclipse (OEPE). But you can still download it without. Give it a try.