1

I am getting this NoClassDefFoundError in one of my programs:

10:26:56,893 ERROR [STDERR] Exception in thread "Timer-4" 
10:26:56,893 ERROR [STDERR] java.lang.NoClassDefFoundError: Could not initialize class
    com.something.plugin.gameserver.common.MetricsRegistrar
10:26:56,893 ERROR [STDERR] at com.something.plugin.gameserver.main.GameServerPlugin.init(GameServerPlugin.java:48)

I know its a class path issue but strangely the GameServerPlugin class where the error occurs and the MetricsRegistrar class its looking for are in the same jar. So one can't be in the class path and the other not right?

I inspected the Jar file it has the class file in question so that not an issue either.

The INDEX.LIST of the jar also has an entry for the package of the MetricsRegistrar class. What else should I check?

For completeness I am building using Ant and running in JBoss.

Usman Ismail
  • 17,999
  • 14
  • 83
  • 165
  • Is the class in the subfolder `com.something.plugin.gameserver.common` of your jar file? – juergen d Apr 25 '12 at 14:42
  • Post the import lines in GameServerPlugin.java and post line 48 and maybe your package structure where MetricsRegistrar.java lives – Sully Apr 25 '12 at 14:43
  • @D3mon import com.something.plugin.gameserver.common.MetricsRegistrar; – Usman Ismail Apr 25 '12 at 14:45
  • Please post the contents of your classpath. – EkcenierK Apr 25 '12 at 14:46
  • 1
    Are you doing something during the class initialization of MetricsRegistrar, like code inside static { ... } ? In http://stackoverflow.com/questions/7325579/java-lang-noclassdeffounderror-could-not-initialize-class-xxx someone had a NoClassDefError too because of this issue. – Luciano Apr 25 '12 at 14:48
  • Does MetricsRegistrar.java have this line? "package com.something.plugin.gameserver.common;" – Sully Apr 25 '12 at 14:50
  • @Luciano That was it its not actually complaining about MetricsRegistrar but a class in its constructor. The error is really misleading. Add that as an answer so I can accept. – Usman Ismail Apr 25 '12 at 15:00
  • @UsmanIsmail done, and glad you could solve it. – Luciano Apr 25 '12 at 15:04

3 Answers3

2

This is a plugin issue: You need to add your classes and imports in your plugin configuration file. Java web applications have web.xml configuration file to be read on first start of the application by the container which runs it,
On the other hand for the Plugins, the plugin configuration file (i.e. ProjectName.plugin.xml) file is loaded and read by your appliction engine that uses this plugin.

GingerHead
  • 8,130
  • 15
  • 59
  • 93
2

Are you doing something during the class initialization of MetricsRegistrar? Like code inside

static { 
 ... 
} 

Here someone had a NoClassDefError too because of this issue.

Community
  • 1
  • 1
Luciano
  • 8,552
  • 5
  • 32
  • 56
0

In general, this means that an unchecked exception was thrown (and not caught) during the static initialization of the class named in the exception, or some other class that it depends on.

If this is the first time that the class load was attempted, then the exception that triggered the problem should be the "cause" chain of the NoClassDefFoundError exception.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216