Archive for Java/J2EE

Flex and Ant Build

One of our projects uses Flex 2 for our presentation layer. We were using Flex builder as the IDE to build the flex components, packaged it with the rest of the J2EE application as war and deployed it. As a practice with rest of the projects we wanted a build automation done in place for continuous integration, as well as saving time building and deploying it to different environments. We could get the ant scripts ready within no time for the J2EE piece of it as it was straightforward and we have done it numerous times. As far as flex goes even though flex ant tasks are available with documentation it wasn’t that easy for us to get things built as flex builder would do it. Sure the ant tasks built the swf files but when we deployed the application on the server we always got this error “RSL Error 1 of 1″ and nothing beyond that. Searching this error resulted in different reasons but nothing concrete in nature.

To be more exact, our application consisted of a Flex model folder containing action scripts common across the other Flex modules. So this had to be set as a run time shared library (RSL) rather than packaging it along with other modules. Packaging with other modules would make it work, but it becomes bulky and performance degrades because the model classes are loaded for each Flex package. To make it a RSL while building the flex components, the model has to be referred as RSL using the attribute in the task. We did this but only got the error mentioned above “RSL Error 1 of 1″. We were clueless at this point and tried out combination of attributes while compiling using mxmlc.

Our only hope remained in identifying what makes the build done by the flex builder make it work and the difference between the parameters it uses and what we use. We knew this because the size of SWF generated out of a Flex builder build was very different from the size that came out of our ant build. Because the build properties are GUI based, how to get what configuration flex builder uses and how it translates to the appropriate compiler options? After exploring the available compilation parameters with mxmlc, we found out the parameter -dump-config would dump the configuration used in a file. We added this parameter to the compiler parameters in the Flex compiler options as shown below in the screen.

dump config option

We compared the configuration that flex builder used versus what we had been using in the mxmlc task, only to find out there wasn’t much difference except for few of the compile time properties which was also present in the flex.config file we were using. The same RSL attribute was present making the model package as reference. We were back to square one wondering what could be the difference and what we are missing. After two days of struggle, a careful re-examination of the configuration in Flex builder when referring the model package in other packages revealed something. Take a look at the snapshot below.

Flex Build Path - Auto Extract SWF - True

The “Auto extract swf: true” was something that we could not find a translation when using the compc ant task and we could not find any documentation mentioning this in the flex ant tasks documentation. We were able to confirm that something is happening here again because of the size difference between what Flex builder generated versus what our ant build generated. There must be a way to produce the package exploded rather than having it packaged as one SWF, just like an exploded war file. Fortunately there was option to do this with the compc task when the directory attribute is set to true and the output attribute holds a directory value. When we were able to do this everything got revealed. Here is a snapshot of the directory structure.

compc output

A look at the files that got generated told us that the SWF that contained the model was having a name of “library.swf”, and when this directory was packaged and added as RSL, there is a mismatch in the reference. The flex runtime binary is looking for MyModel.swf while the only file present is library.swf. That should be the reason for the RSL Error. Also the size when Flex builder built the package was exactly equivalent to the size of the library.swf file present above. So that answers what “Auto extract swf: true” configuration does.

So our ant script was ready, we used one compc task to generate an exploded model directory. Picked the library.swf and copied it to the war with “MyModel.swf”. Another compc task to generate the model packaged so that we can refer it only for compilation for other flex models. Once we did this, everything worked perfectly. So here is the sample ant code (right click and save as, then open in an editor) that made the trick.

Hope this is useful for someone struggling with similar situation and it saves the head cracking time. If someone has found out an easier approach to this please pass that on, we would be happy to learn.

Blink this Flex and Ant Build at blinklist.com    Bookmark Flex and Ant Build at blogmarks    Bookmark Flex and Ant Build at del.icio.us    Digg Flex and Ant Build at Digg.com    Fark Flex and Ant Build at Fark.com    Bookmark Flex and Ant Build at Furl.net    Bookmark Flex and Ant Build at NewsVine    Bookmark Flex and Ant Build at reddit.com    Bookmark Flex and Ant Build at Simpy.com    Bookmark Flex and Ant Build at Spurl.net    Bookmark Flex and Ant Build with wists    Bookmark Flex and Ant Build at YahooMyWeb

Comments (3)      Cosmos

JUnitEE

JUnit is a great tool for unit testing Java applications but it is little difficult to apply it and test the flow from a web application perspective. Particularly say you have unit tests for your DAO you will have to use the JDBC driver connection class to connect to the database and cannot test through JNDI as it requires a server environment. Try JUnitEE. From the site,

JUnitEE provides a TestRunner which outputs HTML and a servlet which can be used as an entry point to your test cases. Building your test harness as a standard J2EE web application means:

  • Your tests are packaged conveniently into a .war file which can easily be moved between servers; you can leave the .war file in the main .ear file and simply avoid enabling the test web application on the production server.
  • Your test classes will be dynamically reloaded by the app server (assuming your server supports this).
  • Your test cases look just like your production code, and can use the same beans (or whatever) you use as a facade for your EJBs.

Blink this JUnitEE at blinklist.com    Bookmark JUnitEE at blogmarks    Bookmark JUnitEE at del.icio.us    Digg JUnitEE at Digg.com    Fark JUnitEE at Fark.com    Bookmark JUnitEE at Furl.net    Bookmark JUnitEE at NewsVine    Bookmark JUnitEE at reddit.com    Bookmark JUnitEE at Simpy.com    Bookmark JUnitEE at Spurl.net    Bookmark JUnitEE with wists    Bookmark JUnitEE at YahooMyWeb

Comments (2)      Cosmos

Fine tuning the JVM

If you are working on a Java/J2EE project one thing that you need to keep in mind is the check on memory and running the web/app server with proper memory parameters. When the JVM (Java Virtual Machine) detects that the garbage collector cannot clear anymore objects because there is none that has no reference and the physical memory limit available for the JVM has been reached, the JVM throws a out of memory error and the application crashes. The optimal mode in which your application can run in the production environment is through fine tuning the JVM parameters. Any J2EE application server has to be started with the java command only just like how you would run a HelloWorld program. A specific class is the starting point to the whole application server. For example this document “Tuning Java Virtual Machines (JVMs)” talks about the fine tuning of JVM for performance in BEA Weblogic server. The concept is almost the same and can be applied for any application server.

Blink this Fine tuning the JVM at blinklist.com    Bookmark Fine tuning the JVM at blogmarks    Bookmark Fine tuning the JVM at del.icio.us    Digg Fine tuning the JVM at Digg.com    Fark Fine tuning the JVM at Fark.com    Bookmark Fine tuning the JVM at Furl.net    Bookmark Fine tuning the JVM at NewsVine    Bookmark Fine tuning the JVM at reddit.com    Bookmark Fine tuning the JVM at Simpy.com    Bookmark Fine tuning the JVM at Spurl.net    Bookmark Fine tuning the JVM with wists    Bookmark Fine tuning the JVM at YahooMyWeb

Comments      Cosmos

Grails Follows Rails

We know the power of Ruby on Rails and what convention over configuration could do. We realized this without any doubt when we built Suggestica and iPolipo. Convention over Configuration is more about built in structure and configuration. All the developers need to do is to use the built in structure and configuration and just focus on the code that will perform the function required by the application. This saves a lot of time in terms of architecture and design and can really help in delivering solutions very quick. With steaming success of Rails and focus on Web 2.0, the industry has started realizing the importance of such framework rather than complex configurations.

GrailsNow Grails is another entry in this arena that uses the Groovy language for its framework. Groovy is an agile dynamic language for the Java Platform with many features that are inspired by languages like Python, Ruby and Smalltalk, making them available to Java developers using a Java-like syntax. As we move on there will be more frameworks like this coming up catering to the languages that are used for web application development. If you want to learn Grails here is the free e-book “Getting Started with Grails” that you can download from InfoQ (needs registration).

Blink this Grails Follows Rails at blinklist.com    Bookmark Grails Follows Rails at blogmarks    Bookmark Grails Follows Rails at del.icio.us    Digg Grails Follows Rails at Digg.com    Fark Grails Follows Rails at Fark.com    Bookmark Grails Follows Rails at Furl.net    Bookmark Grails Follows Rails at NewsVine    Bookmark Grails Follows Rails at reddit.com    Bookmark Grails Follows Rails at Simpy.com    Bookmark Grails Follows Rails at Spurl.net    Bookmark Grails Follows Rails with wists    Bookmark Grails Follows Rails at YahooMyWeb

Comments      Cosmos

Tutorial on Apache Maven2

If you are new to build automation refer my series of posts on build automation.  If you are interested to learn Apache Maven2 you can take a look at the tutorial “Introduction to Apache Maven 2” published in IBM developerWorks (needs registration). You can also refer to Mergere’s whitepaper on Better Builds with Maven.

Blink this Tutorial on Apache Maven2 at blinklist.com    Bookmark Tutorial on Apache Maven2 at blogmarks    Bookmark Tutorial on Apache Maven2 at del.icio.us    Digg Tutorial on Apache Maven2 at Digg.com    Fark Tutorial on Apache Maven2 at Fark.com    Bookmark Tutorial on Apache Maven2 at Furl.net    Bookmark Tutorial on Apache Maven2 at NewsVine    Bookmark Tutorial on Apache Maven2 at reddit.com    Bookmark Tutorial on Apache Maven2 at Simpy.com    Bookmark Tutorial on Apache Maven2 at Spurl.net    Bookmark Tutorial on Apache Maven2 with wists    Bookmark Tutorial on Apache Maven2 at YahooMyWeb

Comments      Cosmos

The Broken Database Connection

We had an issue in one of the project which uses Hibernate for persistence, MySQL for database and JBoss as application server with JNDI connection pooling to the database. The problem was identified when the first iteration of the project went for the QC testing. It stuck after our test person tested the application for a day and came back next day morning and started to continue the testing in the morning. A pile of exception threw up on the screen and none of the links that required bringing data from the database worked. It all threw up exceptions. We had to restart the server to make it start working. We went into the log file and found out an exception constantly being thrown. Here are the first few lines of the exception.

com.mysql.jdbc.CommunicationsException:
Communications link failure due to underlying exception:
java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)


The problem seemed to be the application idle time of more than 8 hrs during night, when all the connections in the pool was cut off by MySQL. This value is one of the system variable settings in MySQL (wait_timeout - 28800 seconds which translates to 8 hours). Obviously changing this setting to a larger number is not the solution. But the program that handles the connections should be smart enough to detect an idle timeout connection close and re-establish the connection. The problem is not peculiar or new, there had been lot of discussions on the same. A google search on the first line of the stacktrace will result in so many discussions around this.

Apparently none of the solutions worked for us and we could not find a solution that addressed this combination Hibernate + MySQL (MySQL Java Connector) + JBoss JNDI. Apache Commons DBCP and C3P0 are couple of frameworks that help in connection pooling. These two frameworks have settings that can reestablish a connection when it is cut. But clueless we were why it didn’t work for us and we tried all sorts of combination.

Finally we decided to take care of the problem by ourselves through code. I am sure when you use Hibernate, the HibernateUtil program that is commonly available has methods to get an Hibernate Session. We had to tweak the openSession method and catch GenericJDBCException and include code to trap the broken pipe condition by checking the corresponding SQL error code and attempt a fresh connection. Here is the openSession and reconnect method from HibernateUtil.java.

Hope this helps if anyone is facing the same issue and any of the solution in the above links does not work.

Blink this The Broken Database Connection at blinklist.com    Bookmark The Broken Database Connection at blogmarks    Bookmark The Broken Database Connection at del.icio.us    Digg The Broken Database Connection at Digg.com    Fark The Broken Database Connection at Fark.com    Bookmark The Broken Database Connection at Furl.net    Bookmark The Broken Database Connection at NewsVine    Bookmark The Broken Database Connection at reddit.com    Bookmark The Broken Database Connection at Simpy.com    Bookmark The Broken Database Connection at Spurl.net    Bookmark The Broken Database Connection with wists    Bookmark The Broken Database Connection at YahooMyWeb

Comments (5)      Cosmos

Taming the classpath

For those of you new to Java one of the biggest challenges is to understand classpath, particularly when working with packages. It can be tricky in windows environment when the file system and path separator is different from many of the other standard UNIX/Linux systems. And classpath issue can simply eat away time and the mistake could be as silly as not having a “.” (which represents the current directory) in the classpath. This IBM article “Managing the Java classpath (Windows)” in IBM Developer Works gives a good detail on how to handle and setup classpath in Windows environment to avoid common pitfalls.

Blink this Taming the classpath at blinklist.com    Bookmark Taming the classpath at blogmarks    Bookmark Taming the classpath at del.icio.us    Digg Taming the classpath at Digg.com    Fark Taming the classpath at Fark.com    Bookmark Taming the classpath at Furl.net    Bookmark Taming the classpath at NewsVine    Bookmark Taming the classpath at reddit.com    Bookmark Taming the classpath at Simpy.com    Bookmark Taming the classpath at Spurl.net    Bookmark Taming the classpath with wists    Bookmark Taming the classpath at YahooMyWeb

Comments      Cosmos

Ruby on Rails or Java and J2EE?

Is it going to be Ruby (on Rails) or Java (and J2EE)? Which one is going to be the future hot technology? Well these questions always remain irrespective of some technology is hot at present or in the future. When it comes to Rails or J2EE for web applications there has been interesting discussions and the question from the Java community has always been what about enterprise class applications and scalability of Rails applications? While there is no concrete answers to these questions here is a good interview in OnJava on “Ruby the rival?” The interview is given by leading experts in the J2EE arena who have recently also got into Ruby and Rails and they answer the above questions.

Blink this Ruby on Rails or Java and J2EE? at blinklist.com    Bookmark Ruby on Rails or Java and J2EE? at blogmarks    Bookmark Ruby on Rails or Java and J2EE? at del.icio.us    Digg Ruby on Rails or Java and J2EE? at Digg.com    Fark Ruby on Rails or Java and J2EE? at Fark.com    Bookmark Ruby on Rails or Java and J2EE? at Furl.net    Bookmark Ruby on Rails or Java and J2EE? at NewsVine    Bookmark Ruby on Rails or Java and J2EE? at reddit.com    Bookmark Ruby on Rails or Java and J2EE? at Simpy.com    Bookmark Ruby on Rails or Java and J2EE? at Spurl.net    Bookmark Ruby on Rails or Java and J2EE? with wists    Bookmark Ruby on Rails or Java and J2EE? at YahooMyWeb

Comments      Cosmos

· « Previous entries

Creative Commons License  This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.