NoClassDefFoundError: caused by ClassNotFoundException - java

My program may use a library when it is present at runtime, but it is not required to have this library to run the program. However, when I run my program (without the library being present), it complains that it is not present for a very specific import:
java.lang.NoClassDefFoundError: nl/lolmewn/stats/api/storage/StorageException
at me.staartvin.plugins.pluginlibrary.Library.<clinit>(Library.java:34) ~[?:?]
at me.staartvin.plugins.pluginlibrary.PluginLibrary.loadLibraries(PluginLibrary.java:105) ~[?:?]
at me.staartvin.plugins.pluginlibrary.PluginLibrary.onEnable(PluginLibrary.java:68) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-latest.jar:git-Spigot-eadd615-4509a14]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-latest.jar:git-Spigot-eadd615-4
9a14]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot-latest.jar:git-Spigot-eadd615-
09a14]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot-latest.jar:git-Spigot-eadd615-45
a14]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot-latest.jar:git-Spigot-eadd615-4
9a14]
at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot-latest.jar:git-Spigot-eadd615-4509a14
at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot-latest.jar:git-Spigot-eadd615-4509a14
at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot-latest.jar:git-Spigot-eadd615-4509a14
at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-latest.jar:git-Spigot-eadd615-4509
4]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot-latest.jar:git-Spigot-eadd615-4509a
]
at java.lang.Thread.run(Uenter code herenknown Source) [?:1.8.0_161]
Caused by: java.lang.ClassNotFoundException: nl.lolmewn.stats.api.storage.StorageException
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_161]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:152) ~[spigot-latest.jar:git-Spigot-eadd615-4
9a14]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:100) ~[spigot-latest.jar:git-Spigot-eadd615-4
9a14]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_161]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_161]
... 14 more
The code that uses this StorageException class is this:
try {
user = stats.getUserManager().loadUser(player.getUniqueId(), stats.getStatManager());
} catch (StorageException e) {
e.printStackTrace();
}
Note that I have many imports using this library. The odd thing is that when I leave out the StorageException import (e.g. change it to a general Exception), it does not give any error anymore, even though there are other imports (from the exact same library) present!
Obviously, I want to use the StorageException class for catching errors, but I can't seem to do this.
How can I solve this issue?

Related

java.lang.NoClassDefFoundError when using IfcJava3DViewer of APSTEX IFC Framework

I'm using APSTEX IFC Framework to creat a IFC 3D Viewer in my Java program.
My code is as follow.
import com.apstex.ifcjava3dviewer.IfcJava3DViewer;
public class JavaViewer2 {
public static void main(String[] args) {
IfcJava3DViewer ifcViewer = new IfcJava3DViewer();
}
}
The error is as followed:
java.lang.NoClassDefFoundError: com/jogamp/opengl/GLCapabilitiesImmutable
at com.apstex.javax.media.j3d.Pipeline$PipelineCreator.run(SourceFile:74)
at com.apstex.javax.media.j3d.Pipeline$PipelineCreator.run(SourceFile:1)
at java.security.AccessController.doPrivileged(Native Method)
at com.apstex.javax.media.j3d.Pipeline.b(SourceFile:91)
at com.apstex.javax.media.j3d.MasterControl.c(SourceFile:858)
at com.apstex.javax.media.j3d.VirtualUniverse.<clinit>(SourceFile:267)
at com.apstex.gui.core.controller.ApplicationController.<init>(SourceFile:1097)
at com.apstex.gui.core.kernel.Kernel.getApplicationController(SourceFile:59)
at com.apstex.ifcjava3dviewer.IfcJava3DPanel.<init>(SourceFile:71)
at com.apstex.ifcjava3dviewer.IfcJava3DViewer.<init>(SourceFile:38)
at test.main.JavaViewer2.main(JavaViewer2.java:7)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLCapabilitiesImmutable
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 11 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.apstex.javax.media.j3d.VirtualUniverse
at com.apstex.javax.media.j3d.Canvas3D.<clinit>(SourceFile:3821)
at com.apstex.gui.ifc.views.view3d.j3d.ModelViewer.<init>(SourceFile:93)
at com.apstex.gui.ifc.views.view3d.j3d.ModelViewer.<init>(SourceFile:79)
at com.apstex.ifcjava3dviewer.IfcJava3DPanel.<init>(SourceFile:1079)
at com.apstex.ifcjava3dviewer.IfcJava3DViewer.<init>(SourceFile:38)
at test.main.JavaViewer2.main(JavaViewer2.java:7)
How can I correct the error?
Thanks for the two commends above to help me solve the problem. By installing a library of JOGL the program works.

UMLPackage.Literals.MODEL throws java.lang.NoClassDefFoundError error

I would like to get the state machine from .uml file created by papyrus. I am parsing the model.uml file using the code below.
ResourceSet set = new ResourceSetImpl();
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource res = set.getResource(URI.createFileURI("resources/model.uml"), true);
EcoreUtil.resolveAll(res);
System.out.println(res.getContents().get(0));
This code works fine and prints the content. But when I try to cast it to Model class using the code below
Model model = (Model) EcoreUtil.getObjectByType(res.getContents(),UMLPackage.Literals.MODEL);
It throws this exception,
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/uml2/types/TypesPackage
at org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.init(UMLPackageImpl.java:1907)
at org.eclipse.uml2.uml.UMLPackage.<clinit>(UMLPackage.java:83)
at org.eclipse.uml2.uml.UMLPackage$Literals.<clinit>(UMLPackage.java:28779)
at mp.m2bt.BTGenerator.main(BTGenerator.java:49)
Caused by: java.lang.ClassNotFoundException: org.eclipse.uml2.types.TypesPackage
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
I am not sure if I am missing anything. I think the problem is in UMLPackage.Literals.MODEL. So, Can anybody help me to fix this issue and get the state machines from the model.
You need the jar org.eclipse.uml2.types in your classpath. This is why the type org.eclipse.uml2.types.TypesPackage cannot be found.

Running jTSS in Eclipse

I am trying to run the Trusted Computing API JSR321 in Eclipse by following the tutorial provide at Getting Started with JSR321 in Windows 7.
After successfully enabling my TPM (manufacturer: STM & version: 1.2).
I tried to run the code given in the tutorial,
import javax.trustedcomputing.tpm.TPMContext;
public class HellowWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
TPMContext context = TPMContext.getInstance();
context.connect(null);
//Do somthing cool here
context.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
I also added the external jar files as Classpaths in eclipse for the IAIK jTSS (jTSS 0.7.1a), they also mentioned that
It is necessary to set the jsr321.tpmcontextimpl property to the classname of your TPMContext implementation.
For example java -cp YourClasspath -Djsr321.tpmcontextimpl=iaik.tc.jsr321.tpm.TPMContextImpl yourjavaapplication.class
So I added the above code by right clicking on the project and going to the Run As -> Run Configuration and in the Arguments tab in the section provided for VM arguments I inserted the following command
-cp C:\Users\workspace\HelloWorld\bin -Djsr321.tpmcontextimpl=iaik.tc.jsr321.tpm.TPMContextImpl HellowWorld
But I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/trustedcomputing/tpm/TPMContext
at HellowWorld.main(HellowWorld.java:10)
Caused by: java.lang.ClassNotFoundException: javax.trustedcomputing.tpm.TPMContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I have already added all the mentioned dependencies in Java Build Paths inside Project Properties.
Kindly suggest a solution.
Thanks

Skype error? Or Eclipse error?

I tried making a simple project for my skype-bot, and it looks like this:
import com.skype.Skype;
import com.skype.SkypeException;
public class SkypeDemo {
public static void main(String[] args) throws SkypeException {
System.out.println(Skype.getVersion());
}
}
But when i started it i get this error:
Exception in thread "main" com.skype.SkypeException: Loading libskype.jnilib failed.
at com.skype.Utils.convertToSkypeException(Unknown Source)
at com.skype.Utils.getProperty(Unknown Source)
at com.skype.Skype.getVersion(Unknown Source)
at SkypeDemo.main(SkypeDemo.java:6)
Caused by: com.skype.connector.LoadLibraryException: Loading libskype.jnilib failed.
at com.skype.connector.ConnectorUtils.loadLibrary(Unknown Source)
at com.skype.connector.osx.SkypeFramework.init(Unknown Source)
at com.skype.connector.osx.OSXConnector.initializeImpl(Unknown Source)
at com.skype.connector.Connector.initialize(Unknown Source)
at com.skype.connector.Connector.connect(Unknown Source)
at com.skype.connector.Connector.assureAttached(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
... 3 more
So how do I fix this error? Keep in mind I have both Skype jars in the build path.
The error is telling you that it cannot load a native library ("libskype.jnilib"). This is (probably) neither Eclipse or Skype's fault.
It is most likely your fault because either the native library is not where it needs to be (or you haven't told Eclipse where to look), or because you have the wrong flavour of native code (DLL, .so or whatever)
(If there was another chained "cause" in the stack trace, it might tell you more ...)
Reference:
This blog post explains how to add a native library to an Eclipse project - http://www.eclipsezone.com/eclipse/forums/t49342.html (In fact, it describes two ways ...)

Java: InvocationTargetException caused by MissingResourceException, but its there

When I run a method on my application, I get the following exception, but the class that is miss 'JarSignerResources' is in my classpath (part of tools.jar). I have never seen an exception like this before, and it only occurs on Linux (not OSX). Can anyone give me a bit of insight into why this would be happening? Thanks.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.ExceptionInInitializerError
at com.wuntee.aat.smali.SmaliWorkshop.signJar(SmaliWorkshop.java:214)
at com.wuntee.aat.smali.SmaliController.rebuildAndSignApk(SmaliController.java:223)
at com.wuntee.aat.view.Gui$13.widgetSelected(Gui.java:354)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at com.wuntee.aat.view.Gui.open(Gui.java:135)
at com.wuntee.aat.view.Gui$1.run(Gui.java:112)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at com.wuntee.aat.view.Gui.main(Gui.java:108)
... 5 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name sun.security.tools.JarSignerResources, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)
at com.wuntee.aat.security.tools.JarSigner.<clinit>(JarSigner.java:96)
... 17 more
This happens at this point in the code:
public static void signJar(String keystore, String keystorePassword, String jarFile, String alias) throws Exception{
JarSigner js = new JarSigner();
js.signJar(keystore, keystorePassword, jarFile, alias);
}
The sun.* packages are not part of the supported, public interface. It is likely you are not using a sun jdk on linux.
A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
see here for details

Categories

Resources