[
https://issues.jboss.org/browse/JBASMP-61?page=com.atlassian.jira.plugin....
]
James Perkins commented on JBASMP-61:
-------------------------------------
For some reason I thought I had already removed the shutdown hook, but clearly I
didn't. IMO it will be better to just remove it rather than hacking it together,
though I find the approach in the PR interesting. I think the shutdown hooks should just
be removed. As long as the JVM is stopped, these really shouldn't be needed.
NoClassDefFoundError in shutdown hook
-------------------------------------
Key: JBASMP-61
URL:
https://issues.jboss.org/browse/JBASMP-61
Project: JBoss AS Maven Plugins
Issue Type: Bug
Affects Versions: 7.5.Final
Environment: Maven 3.1.1, Oracle JDK 1.7.0_45.
Reporter: Vlad Arkhipov
Assignee: James Perkins
{code} <build>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
<executions>
<execution>
<id>start-jboss</id>
<goals>
<goal>start</goal>
</goals>
<phase>package</phase>
<configuration>
<jbossHome>/home/user/jboss</jbossHome>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>{code}
If jbossHome is specified, the following exception occurs
{code}Exception in thread "Thread-2" java.lang.NoClassDefFoundError:
org/jboss/as/plugin/common/IoUtils
at org.jboss.as.plugin.server.StandaloneServer.stopServer(StandaloneServer.java:77)
at org.jboss.as.plugin.server.Server.stop(Server.java:108)
at org.jboss.as.plugin.server.SecurityActions$1.run(SecurityActions.java:41)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: org.jboss.as.plugin.common.IoUtils
at
org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at
org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at
org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227){code}
The reason is that in the shutdown hook the class loader is already closed by Maven and
cannot be used to load new classes. DefaultPlexusContainer.dispose() disposes plugins'
ClassRealms and closes associated URLClassLoaders (if Java version is 7+).
{code}ClassRealm(URLClassLoader).close() line: 282
ClassWorld.closeIfJava7(ClassRealm) line: 113
ClassWorld.disposeRealm(String) line: 97
DefaultPluginRealmCache.flush() line: 189
DefaultPluginRealmCache.dispose() line: 216
PlexusLifecycleManager.dispose(Disposable) line: 408
PlexusLifecycleManager.unmanage() line: 193
DefaultPlexusContainer.dispose() line: 586
MavenCli.doMain(MavenCli$CliRequest) line: 241
MavenCli.main(String[], ClassWorld) line: 158 {code}
As a temporary workaround you can either preload IoUtils class somewhere before Maven
shutdowns (which is brittle) or "respawn" the current classloader in shutdown
hook (which is hacky and brittle too).
Shutdown hooks should be avoided in plugins as Maven documentation says:
http://maven.apache.org/plugin-developers/common-bugs.html#Using_Shutdown....
But it seems there is currently no way to handle Maven shutdown event in a plugin,
isn't it?
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira