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'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0

http://maven.apache.org/xsd/settings-1.0.0.xsd'>

  <!--Maven http://maven.apache.org/settings.html -->
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers>
      <server>
         <id>ACME-ARTIFACTORY-PRIVATE</id>
         <username>administrator</username>
      <password>password</password>
    </server>
  </servers>
	<mirrors>
		<mirror>
		  <id>maven-central</id>
		  <url>http://repo1.maven.org/maven2/</url>
		  <mirrorOf>central,!eclipselink.repository</mirrorOf>
		</mirror>
	</mirrors>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

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:

	<distributionManagement>
		<repository>
			<id>ACME-ARTIFACTORY-PRIVATE</id>
			<name>acme-releases</name>
			<url>http://peabody.internal.acme.com/artifactory/ACME-ARTIFACTORY-PRIVATE</url>
		</repository>
		<snapshotRepository>
			<id>ACME-ARTIFACTORY-PRIVATE</id>
			<name>acme-snapshots</name>
			<url>http://peabody.internal.acme.com/artifactory/ACME-ARTIFACTORY-PRIVATE</url>
		</snapshotRepository>
	</distributionManagement>

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.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

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.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply


8 − = two



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.