Java Reflections 'NoClassDef' error - java

I'm trying to browse all classes that have implemented an interface using the custom libary Reflections. Here is my source :
public static List<IModdable> getAllModClasses() {
Reflections reflections = new Reflections("mod.api.core"); //getting error here
Set<Class<? extends IModdable>> classes = reflections.getSubTypesOf(IModdable.class);
List<IModdable> modList = new ArrayList<IModdable>();
for (Class<? extends IModdable> c : classes)
try {
modList.add((IModdable) c.newInstance());
} catch (Exception ex) {
err(String.format("Could not load mod %s !", c.getName()));
}
return modList;
}
error:
Exception in thread "Client thread" java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:100)
at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24)
at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30)
at org.reflections.Reflections.scan(Reflections.java:238)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.<init>(Reflections.java:129)
at org.reflections.Reflections.<init>(Reflections.java:170)
at org.reflections.Reflections.<init>(Reflections.java:143)
at mod.api.core.CoreProvider.getAllModClasses(CoreProvider.java:17)
at mod.api.core.ModCore.onLoad(ModCore.java:13)
at net.minecraft.client.Minecraft.run(Minecraft.java:405)
at net.minecraft.client.main.Main.main(Main.java:114)
at Start.main(Start.java:11)
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
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)
... 13 more
The mod.api.core package exits. So that shouldn't be the error.

java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
You can fix the issue by adding javassist-3.12.1.GA.jar to your classpath

Related

java.lang.NoClassDefFoundError: com/sun/jna/win32/StdCallLibrary after exporting to jar file

I'm trying to write a java application to change my desktop wallpaper using cmd.
The code I have written so far:
package me.kaes3kuch3n.main;
import java.util.HashMap;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.UINT_PTR;
import com.sun.jna.win32.*;
public class WallpaperUpdater {
public static void main(String[] args) {
if(args.length != 1) {
System.err.println("Usage: java -jar WallpaperUpdater.jar <path_to_wallpaper>");
} else {
String path = args[0];
SPI.INSTANCE.SystemParametersInfo(
new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),
new UINT_PTR(0),
path,
new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));
}
}
public interface SPI extends StdCallLibrary {
//from MSDN article
long SPI_SETDESKWALLPAPER = 20;
long SPIF_UPDATEINIFILE = 0x01;
long SPIF_SENDWININICHANGE = 0x02;
SPI INSTANCE = (SPI) Native.loadLibrary("user32", SPI.class, new HashMap<Object, Object>() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
}
});
boolean SystemParametersInfo(
UINT_PTR uiAction,
UINT_PTR uiParam,
String pvParam,
UINT_PTR fWinIni
);
}
}
It works just fine when I'm running it using Eclipse but after exporting it to a jar file it throws an error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/win32/StdCallLibrary
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at me.kaes3kuch3n.main.WallpaperUpdater.main(WallpaperUpdater.java:17)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.win32.StdCallLibrary
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)
... 13 more
I've added both the jna.jar and the jna-platform.jar to the build path, but it won't work. What am I missing?

Getting org/apache/poi/UnsupportedFileFormatException

I tried the following code to read the contents of .xlsm file
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class ReadMacroExcel {
public static void main(String[] args) {
try {
FileInputStream f=new FileInputStream("C:\\Users\\user\\Documents\\samplewkbk.xlsm");
org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(f);
System.out.println(workbook);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I am getting the following expection:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/UnsupportedFileFormatException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:87)
at wipro.ReadMacroExcel.main(ReadMacroExcel.java:13)
I use the following jar files:
poi-ooxml-3.11.jar
poi-3.9.jar
xmlbeans-2.3.0.jar
poi-ooxml-schemas-3.7-beta1.jar
dom4j-1.6.jar

selenium web driver java.lang.NoClassDefFoundError: com/google/gson/JsonSyntaxException

trying to run simple test selenium Web Driver program which is mentioned below:
package com.abc;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Mock_Exam {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
}
}
after running as java application getting the below error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/JsonSyntaxException
at org.openqa.selenium.firefox.Preferences.readDefaultPreferences(Preferences.java:95)
at org.openqa.selenium.firefox.Preferences.<init>(Preferences.java:65)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:87)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:77)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:66)
at org.openqa.selenium.firefox.FirefoxDriver.getProfile(FirefoxDriver.java:262)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at com.kesdee.ia.Mock_Exam.main(Mock_Exam.java:14)
Caused by: java.lang.ClassNotFoundException: com.google.gson.JsonSyntaxException
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)
... 13 more
FireFox version: 36.0.1
Selenium: selenium-java-2.45.0
You miss the gson-<version>.jar: in your classpath. Download add add it.

Errors with JADE platform

Good evening, I tried to use the JADE platform (official site -> http://jade.tilab.com/)
I followed tutorials that I found on youtube
Here's the code
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.util.ExtendedProperties;
import jade.util.leap.Properties;
import jade.wrapper.AgentContainer;
import jade.wrapper.ControllerException;
public class MainContainer {
public static void main(String[] args) {
try {
Runtime rt = Runtime.instance();
Properties p = new ExtendedProperties();
p.setProperty(Profile.GUI, "true");
ProfileImpl pc = new ProfileImpl(p);
AgentContainer container = rt.createAgentContainer(pc);
container.start();
} catch (ControllerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But when I run the program I get errors like:
Exception in thread "main" java.lang.NoClassDefFoundError: jade/wrapper/ControllerException
****at java.lang.Class.getDeclaredMethods0(Native Method)
****at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
****at java.lang.Class.getMethod0(Unknown Source)
****at java.lang.Class.getMethod(Unknown Source)
****at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
****at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: jade.wrapper.ControllerException
****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)
****... 6 more
How To fix it please !
PS: I'm on windows7
You are missing jade's jar from your classpath. You could add it to the -cp parameter of java. E.g.:
java -cp JADE-all-4.3.2.zip MainContainer

ServerException is being thrown while binding RMI service

I'm trying to build simple echo server as RMI application (step by step as it's described in Sun tutorial).
All source code is shown below, it's very simple:
package test;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface EchoServer extends Remote {
public String sendString (String str) throws RemoteException;
}
package test;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class EchoServerImpl extends UnicastRemoteObject implements EchoServer {
public EchoServerImpl () throws RemoteException {
super ();
}
public String sendString (String str) throws RemoteException {
return str.toUpperCase();
}
}
package test;
import java.rmi.Naming;
public class RMIServer {
public RMIServer () {
try {
EchoServer eServer = new EchoServerImpl ();
Naming.rebind ("rmi://localhost:1099/EchoService", eServer); // <--exception
} catch (Exception e) {
e.printStackTrace ();
}
}
public static void main(String[] args) {
new RMIServer ();
}
}
I compile code with rmic and I see file EchoServerImpl_Stub.class. After that I run 'rmiregistry' and then I start RMIServer. And at that moment I see ServerException:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.EchoServerImpl_Stub
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at test.RMIServer.(RMIServer.java:10)
at test.RMIServer.main(RMIServer.java:17)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.EchoServerImpl_Stub
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: test.EchoServerImpl_Stub
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 java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 12 more
I think it's a common problem and it's probably connected with wrong deploying. How to fix it?
I think it's your rmiregistry classpath. The test.EchoServer interface needs to be accessible to the rmiregistry itself. Set your CLASSPATH environment variable before you run up the rmiregistry e.g.
C:\>set CLASSPATH="MyBinFolder"
C:\>rmiregistry
Also, rmic is a hangover from before Java 5. It isn't necessary to run it anymore. Just run your server and client as normal and the proxies will be created dynamically.
Regards,
MK

Categories

Resources