[jboss-jira] [JBoss JIRA] (JBASMP-61) NoClassDefFoundError in shutdown hook

James Perkins (JIRA) issues at jboss.org
Sun Feb 16 14:13:47 EST 2014


    [ https://issues.jboss.org/browse/JBASMP-61?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12945040#comment-12945040 ] 

James Perkins commented on JBASMP-61:
-------------------------------------

This is definitely a strange error. I saw it consistently while I was looking at it the issue. When I got some time to work on it, the issue just went away. As the comment says we're not supposed to use shutdown hooks in plugins. The problem is when I removed the shutdown hook it seems to sometimes leave the JVM running which is bad. I haven't found a solution I really like for this. I might have to use the class loading hack in the PR, but I have to admit I don't love it. It could work as at least a temporary fix I guess. 
                
> 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_Hooks.
> 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


More information about the jboss-jira mailing list