Tips, Tricks and Troubleshooting of Embedded GlassFish
This blog lists the tips, tricks and answers to some of the commonly asked questions on Embedded GlassFish. This list is not sorted in any order. As I recalled I just listed them out here, and will add more as I come across more tips n tricks.
Which version of Maven is supported by Embedded GlassFish Maven Plugin?
org.glassfish:maven-embedded-glassfish-plugin supports Maven 2 and Maven 3
(4.0-SNAPSHOT and 3.1.2 versions of the plugin are verified maven 2.0.1, maven 2.2.1 and Maven 3.0.4)
How do I deploy multiple applications using Embedded GlassFish Maven Plugin?
My web application's WEB-INF/lib bundles some libraries. But if the same library classes are also bundled in Embedded GlassFish's Uber Jar (viz., glassfish-embedded-all.jar or glassfish-embedded-web.jar), then what is in uber jar takes precedence. How to make my WEB-INF/lib's library take precedence?
An example of that could be org.objectweb.asm.ClassWriter. If the application wants to bundle a different version of this library, but since uber.jar's classes take precedence, it may result in java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.
So, to fix this issue and make your WEB-INF/lib's library classes to take precedence, you need to just include WEB-INF/sun-web.xml that contains:
How to debug my application while using Embedded GlassFish Maven Plugin?
Add "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009" to your MAVEN_OPTS environment variable, and then run 'mvn' command.
Once you see "Listening for transport dt_socket at address: 9009" in your terminal, attach you IDE to 9009 debug port.
(Choose your port as opposed to 9009 above)
In my maven tests I use unit tests via surefire plugin and embed GlassFish directly with org.glassfish.embeddable APIs without using Embedded GlassFish Maven Plugin. How do I debug my test and Java EE application?
Run you mvn like this:
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009" verify
and once you see "Listening for transport dt_socket at address: 9009" in your terminal, attach your IDE to 9009 debug port.
Since GlassFish is embedded inside your test, you can debug both your test and Java EE application.
How do I see man pages for Embedded GlassFish Maven Plugin?
In the directory where you have a pom.xml that contains org.glassfish:maven-embedded-glassfish-plugin section, just run this command:
mvn help:describe -Dplugin=embedded-glassfish; # To get high level details about goals.
mvn help:describe -Dplugin=embedded-glassfish -Ddetail; # With complete details.
For latest 4.0-SNAPSHOT binaries of Embedded GlassFish and Maven Plugin, which maven repository should be used?
It's this one : https://maven.java.net/content/repositories/snapshots
You can include this repository in your pom.xml like this:
Where are Embedded GlassFish' samples/tests?
I am seeing "java.lang.IllegalStateException: Provider already mapped", what should I do?
Make sure the classpath to your program does not contain duplicate Embedded GlassFish' jars.
Watch out for more tips and in this space...