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

Vlad Arkhipov (JIRA) issues at jboss.org
Thu Dec 12 12:06:33 EST 2013


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

Vlad Arkhipov commented on JBASMP-61:
-------------------------------------

Without this shutdown hook JBoss server remains running if, for some reason, Maven build fails after jboss-as-plugin:start. This may be fatal when running on CI server.
                
> 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