Home » Java » Enterprise Java » Build GlassFish 4.0 Snapshots Yourself

About Peter Pilgrim

Peter Pilgrim

Build GlassFish 4.0 Snapshots Yourself

This post is about building GlassFish 4.0 snapshots release yourself and includes hacks. I found the official Instruction for FullBuild of GlassFish and then decided to build the server myself. Sometimes, you may not want to wait for the GlassFish build files to be promoted by the team. In this entry, I reference Artifactory as a private Maven repository, of course, you can use something else as well. Checkout the source code for GlassFish 4.0 yourself from Subversion:

svn checkout https://svn.java.net/svn/glassfish~svn/trunk/main glassfish-main

You need to hack the Maven Settings file for your workstation to exclude Eclipse artifacts.Here is an example of the settings.xml, which I configured.

<settings xmlns='http://maven.apache.org/SETTINGS/1.0.0'


  <!--Maven http://maven.apache.org/settings.html -->

Before we can compile the entire GlassFish code, we need to hack POM files so that they install artifacts into our private Artifactory server instead of the Maven Central. Add the following Stanza to the POM files in the distribution:


In the above Stanza, edit the definitions from ACME to the Artifactory server that you privately own, then copy it the following POM files:

  • main/pom.xml
  • main/appserver/javaee-api/pom.xml
  • main/appserver/pom.xml
  • main/nuclues/pom.xml

This is a nasty hack, because I don’t like that you can’t set change the deployment server and credentials from a configuration. Other source code allow configuration of the deployment server through Maven Profiles or even property files. Make sure that your Maven settings are correct for Artifactory deployment and also we set up Maven build process. Set the environment variable MAVEN_OPTS so that there Maven has enough memory and the permanent generation is high enough to avoid out of memory exceptions during compilation.

MAVEN_OPTS=-Xmx1024m -Xms256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled

If you have 16GB RAM workstation, why not just max it out for compiling the entire GlassFish? The Garbage Collection algorithm is changed to the concurrent mark and sweep algorithm and we also set the enabled class unloading enabled. You are ready to compile, entering the following commands:

cd glassfish-main
svn update
mvn clean
mvn install -DskipTests=true

Make yourself a hot beverage and snack for about 20 minutes on a decent Intel Core i5/i7 machine (2012). Have a break. Notice that we avoid running the unit tests here, we skip the tests, because we just want a working release in repo, quickly, which is just not to say testing is bad. After successful compilation of all of the modules, now you are ready to deploy to the private Maven repository. If you have followed the earlier instruction, about copying the stanza to the individual POM files, then you can execute this command from root.

cd glassfish-main
mvn deploy -DskipTests=true

After deploying the artifacts to Artifactory, check the repository for snapshot 4.0 release, they should all be there. Now descend to the Java EE project folder. Hack the POM file, glassfish-main/appserver/javaee-api/javax.javaee-api/pom.xml. It is missing the maven source plugin in the build section, and therefore, by default, it does not generate the sources JAR, which is useful for seeing the new JavaEE 7 APIs! Find the XPath project/build/plugins and append the following stanza to this POM.


Execute the following command line, to deploy the Java EE api artifacts

cd glassfish-main/appserver/javaee
mvn deploy -DskipTests=true

For some reason, the main execution does not install javax.javaee-api artifacts automatically. Executing this line generates JAR and SOURCES JAR for the three underlying modules: javax.javaee-api, javax.javaee-web-api and javax.javaee-endorsed-api. Go Artifactory and see that the artifacts have all been deployed. You can then write a Gradle build file like this:

repositories {
    maven {
        credentials {
            username 'administrator'
            password 'passowrd'
        url 'http://peabody.internal.acme.com/artifactory/ACME-ARTIFACTORY-PRIVATE'
    maven {
        url 'https://maven.java.net/content/groups/promoted'
    maven {
        url 'http://repository.jboss.org/nexus/content/groups/public'

dependencies {
    providedCompile 'org.glassfish.main.extras:glassfish-embedded-all:4.0-SNAPSHOT'
    providedCompile 'javax:javaee-api:7.0-bpeter-private'
    providedCompile 'javax:javaee-web-api:7.0-bpeter-private'

    compile     'org.glassfish.main.extras:glassfish-embedded-all:4.0-SNAPSHOT'
    compile     'javax:javaee-api:7.0-bpeter-private'

    testCompile 'junit:junit:4.10'

Especially, note that the build version are annotated as 7.0-bpeter-private. The last piece of the puzzle, which I have not yet worked out is how to configure the build.id Maven property so that I can customize the build number. It is a mystery, still. If you happen to know the answer, please give me a bell. Cheers!

Reference: Build GlassFish 4.0 Snapshots Yourself from our JCG partner Peter Pilgrim at the Peter Pilgrim’s blog blog.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments