Loading Resources from an Imported JAR

The ClassLoader can be used to reference a resource in a JAR.  For example, if I packaged a JAR with a file called file.xml in the directory path/in/JAR, I would use the code below.

this.getClass().getClassLoader().getResource(“path/in/JAR/file.xml”);

If you need to reference other files, it may be smart to use a Java Enum to store these locations for better organization.

JAXB xjc Compiler Content Tree Generation Issue

The JAXB xjc compiler created a generic content tree called “content” in the type of List<Object>, which is too generic for use.  Ideally, xjc should create a content tree with specific types (e.g. List<Type>).  JAXB calls this generic property (i.e. List<Object> content) the “catch-all” property.  The accessors for this property are generic as well -List<Object> getContent().  After many hours of hacking the XML schemas, I realized the generated class has the reason as part of its comments on why xjc created a generic property instead of type specific properties.  I should’ve known.

In conclusion, if the xjc compiler isn’t generating what you are expecting, check the comments in the generated java code first.

Installing Glassfish Server Adapter in Eclipse 3.5

I had some trouble installing the glassfish server adapter on my new workstation, so I wanted to write this down so that I won’t forget again. Use the install site “http://ajax.dev.java.net/eclipse&#8221; instead of going through the new server adapter interface.

Note: This install site is not mine and may get removed or modified. Search for “glassfish server adapter for eclipse 3.5” for other alternatives.

Dynamic Reloading (Hot Deployment) on Glassfish 2.1

This is how I set up dynamic reloading (hot deployment) on Glassfish Application Server v2.1. This is a basic outline of how dynamic reloading works, and some steps may be automated with plugins and scripts.

Set up
 
1. Ensure that dynamic reloading is enabled in the Glassfish Admin Console.
    a. Navigate to Application Server configurations
    b. Check the Enable Reload box
    c. Apply Settings
 
2. Set up the FileSync plugin.
    a. Follow instructions to install here http://andrei.gmxhome.de/filesync/index.html 
    b. Set project properties in Eclipse to map target directory (where built classes are stored) and map it to the appropriate exploded directory in your domain within the Glassfish home directory
 
Procedure
 
1. Modify Java file(s).
 
2. Build Modified Files
    Skip step 3 if the files were built internally within Eclipse.
 
3. Refresh Eclipse files.
    The modified files should now be synchronized with the dynamic deployment directory.

4. Modify or "touch" .reload file.

    An update in the last modified time for the .reload file signals glassfish to dynamically reload the application.
    The server log will show the progress of the application unloading and loading.

5. Test the modified file.

    I tested this by adding log outputs to existing Java files.

   

Setting up JBoss Seam in Ubuntu

This post has moved to my new blog

This post describes the steps I took to set up JBoss AS 5.1.0 and Seam 2.2.0 in Ubuntu 9.04 on my local machine.  This post assumes Ubuntu 9.04 is already installed.

1. List of Technologies Used

  • Ubuntu 9.04 Jaunty Jackalope Desktop 32-bit
  • Sun JDK 6
  • Eclipse 3.5 Galileo
  • JBoss Application Server (AS) 5.1.0 GA
  • Seam Engine 2.2.0 GA
  • MySQL 5.0
  • JBoss AS Tools 2.1.0-M2
  • Seam Tools 3.1.0-M3
  • Apache Ant 1.7.1

2. Installation Procedures

a. Sun JDK 6

Install Package

1. Open Synaptic Package Manager

2. Install package sun-java6-jdk and its dependencies

Set up Environment

1. Open ~/.profile with a text editor

2. Add environment variable JAVA_HOME to point to your Java directory

e.g. export JAVA_HOME = /usr/lib/jvm/java-6-sun-1.6.0.14

2. Update environment variable PATH to include your Java/bin directory

e.g. export PATH = $JAVA_HOME/bin:$PATH

b. Eclipse 3.5 Galileo

Install Package

1. Open URL http://www.eclipse.org/downloads/

2. Download the appropriate Eclipse IDE package

This post uses Eclipse 3.5 Galileo for Linux 32-bit

3. Extract the contents of the package to a known directory

This post uses ~/Programs/eclipse

c. JBoss Application Server 5.1.0 GA

Install Package

1. Open URL http://www.jboss.org/jbossas/downloads/

2. Download the appropriate JBoss AS binary package

This post uses jboss-5.1.0.GA.zip

3. Extract the contents of the package to a known directory

This post uses ~/Programs/jboss-5.1.0.GA

Set up Environment

1. Open ~/.profile with a text editor

2. Add environment variable JBOSS_HOME to point to your JBoss directory

e.g. export JBOSS_HOME = ~/Programs/jboss-5.1.0.GA

d. Seam Engine 2.2.0 GA

Install Package

1. Open URL http://seamframework.org/Download

2. Download the appropriate Seam Engine binary package

This post uses jboss-seam-2.2.0.GA.zip

3. Extract the contents of the package to a known directory

This post uses ~/Programs/jboss-seam-2.2.0.GA

e. MySQL 5.0

Install Package

1. Open Synaptic Package Manager

2. Install package mysql-server-5.0 and its dependencies

3. Set up the administrative account

The dialog for administrative setup should pop up automatically during the install

4. Open URL http://dev.mysql.com/downloads/connector/j/5.0.html

5. Download the appropriateMySQL Connector/J binary package

6. Extract mysql-connector-java-5.0.8-bin.jar to ~/Programs/jboss-5.1.0.GA/server/default/lib

Set up Environment

1. Open Terminal

2. Log in to mysql using the administrative account

$ mysql –user=<username> –password=<password>

3. Create databases

create database jbossas;

create database test;

f. JBoss AS Tools 2.1.0-M2

Install Package

1. Open Eclipse

2. Navigate to Help -> Install New Software

3. Add Software Site http://download.jboss.org/jbosstools/updates/development

4. Install JBoss AS Tools 2.1.0-M2 and its dependencies

g. Seam Tools 3.1.0-M3

Install Package

1. Open Eclipse

2. Navigate to Help -> Install New Software

3. Add Software Site http://download.jboss.org/jbosstools/updates/nightly/trunk/

4. Install Seam Tools 3.1.0-M3 and its dependencies

h. Apache Ant 1.7.1

Install Package

1. Open URL http://ant.apache.org/bindownload.cgi

2. Download appropriate Ant binary package

This post uses apache-ant-1.7.1-bin.zip

3. Extract the contents of the package to a known directory

This post uses ~/Programs/apache-ant-1.7.1

Set up Environment

1. Open ~/.profile with a text editor

2. Add environment variable ANT_HOME to include your Ant directory

e.g. export ANT_HOME = ~/Programs/apache-ant-1.7.1:$PATH

3. Update environment variable PATH to include your Ant/bin directory

e.g. export PATH = $ANT_HOME/bin:$PATH

3. Configuring JBoss AS in Eclipse

1. Open Eclipse IDE

2. Select J2EE Perspective

a. Navigate to Window -> Open Perspective -> Other

b. Select J2EE

3. In the lower panel, select the Servers tab

4. Add a new JBoss 5.1 Server

The option to create a JBoss 5.1 Server is available with JBoss AS Tools

5. Configure the Server

This post’s JBoss AS home directory is ~/Programs/jboss-5.1.0.GA

This post’s server configuration is “default”

5. Run the Server

6. Test URL http://localhost:8080

The JBoss AS default page should be displayed

4. Creating a New Project

1. Open Terminal

2. Navigate to the Seam Engine directory

3. Add execute permission to seam

$ chmod a+x seam

4. Run seam setup

$ ./seam setup

database is mysql

jdbc driver jar filepath is ~/Programs/jboss-5.1.0.GA/server/default/lib/mysql-connector-java-5.0.8-bin.jar

jdbc driver class is com.mysql.jdbc.Driver

jdbc datasource class is com.mysql.jdbc.jdbc2.optional.MysqlDataSource

jdbc url is jdbc:mysql://localhost:3306/dbname

5. Run seam create-project

$ ./seam create-project

6. Run seam explode

$ ./seam explode

7. Generate entities for any preexisting database tables

$ ./seam generate-entities

8. Import the newly created project as an existing project in Eclipse

9. Configure the Project’s properties to use the correct Seam Engine

a. Navigate to Properties -> Seam Settings

b. Add the Seam 2.2 runtime engine

The option to add Seam 2.2 is available with Seam Tools 3.1.0-M3 (Nightly Build)

5. Conclusion

You should be set!  I wrote this post after I configured my local machine, so it is written to the best of my memory.