Skip to main content

Cargo support for GlassFish v2

Posted by kohsuke on October 6, 2008 at 2:24 PM PDT

In early September, Cargo project pushed 1.0 alpha-6 release, which contains my improvement of better pluggability support. With this and the cargo-core-containers-glassfish module that I just pushed, you can now automate GlassFish v2 through Cargo.

In this cargo-core-containers-glassfish release of 1.0 alpha-6, we have the support for starting/stopping GlassFish and deploying artifacts to it. For this to work, you need to have GlassFish installed first, then tell Cargo where it is.

Cargo can be used in many different ways, such as the programmatic API, Ant tasks, and Maven plugins. You can see more details about these in the Cargo website, but for example, the following Ant build script fragment shows you how to start GF with some wars deployed.
The key thing to remember is that the GlassFish has the container ID of "glassfish2".

<br /><taskdef resource="cargo.tasks"><br />  <classpath><br />    <pathelement location="path/to/cargo.jar"/><br />    <pathelement location="path/to/cargo-core-container-glassfish-1.0-alpha-6.jar"/><br />  </classpath><br /></taskdef><br /><br /><cargo containerId="glassfish2" home="/path/to/gfv2/installation/directory" output="target/output.log"<br />    log="target/cargo.log" action="start"><br />  <configuration><br />    <property name="cargo.servlet.port" value="8180"/><br />    <deployable type="war" file="path/to/hudson.war"/><br />  </configuration><br /></cargo><br />

Cargo helps automation of containers, so it's a very useful project for automated tests (and yes, you can use this with Hudson, which has a plugin to talk to Cargo.)

I hope to merge this module to the Cargo project when things are stable, so please let me know how it's working for you. Also, GlassFish v3 support is also on the TODO list.

Related Topics >>

Comments

Hi, I am trying to start glassfish2 using your ant script , but have error with configuration. Could you help me resolve it 1) ant target ERROR: org.codehaus.cargo.container.ContainerException: Cannot create configuration. There's no registered configuration for the parameters (container [id = [glassfish2], type = [installed]], configuration type [standalone]). Actually there are no valid types registered for this configuration. Maybe you've made a mistake spelling it? at org.codehaus.cargo.generic.spi.AbstractGenericHintFactory.createImplementation(AbstractGenericHintFactory.java:143) at org.codehaus.cargo.generic.spi.AbstractIntrospectionGenericHintFactory.createImplementation(AbstractIntrospectionGenericHintFactory.java:86) at org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory.createConfiguration(DefaultConfigurationFactory.java:387) at org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory.createConfiguration(DefaultConfigurationFactory.java:374) at org.codehaus.cargo.ant.ConfigurationElement.createConfiguration(ConfigurationElement.java:209) at org.codehaus.cargo.ant.CargoTask.makeContainer(CargoTask.java:751) at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:449) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288) at sun.reflect.GeneratedMethodAccessor723.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:357) at org.apache.tools.ant.Target.performTasks(Target.java:385) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329) at org.apache.tools.ant.Project.executeTarget(Project.java:1298) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1181) at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:277) at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:460) at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151) BUILD FAILED (total time: 0 seconds)

Hello Kohsuke, I get the same error message like david. Can you mail me a working pom.xml? oliver

You need to express the plugin dependency. Sadly this page does not allow easy posting of XML so I am unable to post a working config ... how bad is that ?

You need to express the plugin dependency. Sadly this page does not allow easy posting of XML so I am unable to post a working config ... how bad is that ?

The maven config is: org.codehaus.cargo cargo-maven2-plugin 1.0-alpha-6 glassfish2 ${glassfish.home} local org.codehaus.cargo cargo-core-container-glassfish 1.0-alpha-6

It is in the cargo's repository, which should be mirrored into the central repository shortly.

The source code is in the cargo-contrib module (if you are trying to check out from SCM -- see POM.) The source jar is also available in the Maven repository.

Do you have an example of a working maven2 configuration? I have looked around through the cargo documentation for hours, and have not been able to get it working. In my POM I have: <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.0-alpha-6</version> <configuration> <container> <containerId>glassfish2</containerId> </container> <type>local</type> <home>/home/emalotau/glassfish-v2ur2/domains</home> </configuration> </plugin> On the command-line I type: mvn cargo:start and then maven says: Cannot create configuration. There's no registered configuration for the parameters (container [id = [glassfish2], type = [installed]], configuration type [standalone]). Actually there are no valid types registered for this configuration. Maybe you've made a mistake spelling it?

hi Kohsuke, where can I find the source code or the options that it accepts? It doesn't appear in the cargo's repository

To use this with Maven, specify a plugin dependency, as raym0nd says. See http://pastebin.com/f4a20e599 for the example.

No, the ID is correct --- I'm using it myself. Please use the CARGO issue tracker to report problems in glassfish cargo support. A blog comment section is not a good place for user support.

It looks like the form ate my XML. The short of it is that I'm using the suggested cargo taskdef and and tasks as mentioned in the description and still get the same exception :-( .... thanks

I found the alpha-6 jars: * Core uberjar: http://repository.codehaus.org/org/codehaus/cargo/cargo-core-uberjar/1.0... * Ant Tasks: http://repository.codehaus.org/org/codehaus/cargo/cargo-ant/1.0-alpha-6/... * Glassfish Support: http://repository.codehaus.org/org/codehaus/cargo/cargo-core-container-g... And I tried the following: $${libs.cargo-core-uberjar-1.0-alpha-6.classpath} ${libs.cargo-core-uberjar-1.0-alpha-6.classpath} $${libs.cargo-ant-1.0-alpha-6.classpath} ${libs.cargo-ant-1.0-alpha-6.classpath} $${libs.commons-discovery-0.4.classpath} ${libs.commons-discovery-0.4.classpath} $${libs.commons-logging-1.1.classpath} ${libs.commons-logging-1.1.classpath} $${libs.dom4j-1.6.1.classpath} ${libs.dom4j-1.6.1.classpath} $${libs.jaxen-1.1-beta-8.classpath} ${libs.jaxen-1.1-beta-8.classpath} $${libs.cargo-core-container-glassfish-1.0-alpha-6.classpath} ${libs.cargo-core-container-glassfish-1.0-alpha-6.classpath} Where libs.xxx.classpath refers the the jar file for the libraries mentioned. I continue to get the same errors: org.codehaus.cargo.container.ContainerException: Cannot create configuration. There's no registered configuration for the parameters (container [id = [glassfish2], type = [installed]], configuration type [standalone]). Actually there are no valid types registered for this configuration. Maybe you've made a mistake spelling it? at org.codehaus.cargo.generic.spi.AbstractGenericHintFactory.createImplementation(AbstractGenericHintFactory.java:143) at org.codehaus.cargo.generic.spi.AbstractIntrospectionGenericHintFactory.createImplementation(AbstractIntrospectionGenericHintFactory.java:86) at org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory.createConfiguration(DefaultConfigurationFactory.java:356) at org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory.createConfiguration(DefaultConfigurationFactory.java:343) at org.codehaus.cargo.ant.ConfigurationElement.createConfiguration(ConfigurationElement.java:201) at org.codehaus.cargo.ant.CargoTask.makeContainer(CargoTask.java:751) at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:449) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288) at sun.reflect.GeneratedMethodAccessor881.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:357) at org.apache.tools.ant.Target.performTasks(Target.java:385) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337) at org.apache.tools.ant.Project.executeTarget(Project.java:1306) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1189) at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:273) at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:499) at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151) Any hints?

Hi Kohsuke, I'm trying your glassfish support plugin for cargo, but I'm receiving the same error as in the previous comment: org.codehaus.cargo.container.ContainerException: Cannot create configuration. There's no registered configuration for the parameters (container [id = [glassfish2], type = [installed]], configuration type [standalone]). Actually there are no valid types registered for this configuration. Maybe you've made a mistake spelling it? I am using the 1.0-uberjar from cargo, and the 1.0 verion of the glassfish-support jar found from the link you provide above. The documentation on the site doesn't seem to describe the extension mechanism improvements you contributed to cargo, and I can't find the alpha6 jar (and have been too lazy to try to build my own so far). Did your improvements not make it into the 1.0 release? Am I doing something wrong? Thanks in advance for anything you can add.

progress toward a solution...

I downloaded the source of cargo and compiled a custom version for myself so that I could debug things. It seems the source of my trouble has to do with the order in which the classloader is selected (at least when run via Ant 1.7.1).
In order to get around the error message:
There's no registered configuration for the parameters (container [id = [glassfish2], type = [installed]], configuration type [standalone])

I had to make a small modification to the list() method in AbstractFactoryRegistry so that the ClassLoader associated with the AbstractFactoryRegistry class is used to load the GlassFishServiceFactory, rather than the "context class loader".
So instead of doing this:
if (cl == null)
{
cl = Thread.currentThread().getContextClassLoader();
}
if (cl == null)
{
cl = AbstractFactoryRegistry.class.getClassLoader();
}

I changed it to do this:
if (cl == null)
{
cl = AbstractFactoryRegistry.class.getClassLoader();
}
if (cl == null)
{
cl = Thread.currentThread().getContextClassLoader();
}
.....
I have no idea whether this is a good idea, but this was what was necessary...is there a reason that all loaders are not used to perform this search?

I'm willing to pursue this a bit further if you think it makes sense, I'm just looking for a bit of guidance...thanks!
.....
PS: This comment form makes it very difficult to format comments :-(

...more...

I eventually settled on this, which seems pretty safe: ...
ClassLoader cl = classLoader;
ClassLoaders loaders = new ClassLoaders();
cl = AbstractFactoryRegistry.class.getClassLoader();
if (cl != null) {
loaders.put(cl);
}
cl = Thread.currentThread().getContextClassLoader();
if (cl != null) {
loaders.put(cl);
}
cl = JDKHooks.getJDKHooks().getSystemClassLoader();
if (cl != null) {
loaders.put(cl);
}
if (loaders.size() == 0) {
// this is not our day. bail out.
return Collections.EMPTY_LIST;
}
...

Patch submitted to Cargo people...

Attached to issue here: http://jira.codehaus.org/browse/CARGO-491