com.google.protobuf.ExtensionRegistryLite ClassNotFoundException in Eclipse Plugin - java

I am trying to progamatically compile and load protobuf code in an eclipse plugin but for some reason it gives me this error:
java.lang.NoClassDefFoundError: com/google/protobuf/ExtensionRegistryLite
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
I know I have the dependencies set up correctly because I am able to import ExtensionRegistroyLite and use it. Also when I run this code as a Java application it works fine. Here is how I am compiling and loading the class:
compiler.run(null, null, null, "-d", "path/to/dir, "-classpath", "protobuf-java-3.11.4.jar", "myProtoClass.java")
URL url = protoDir.toUri().toURL();
URL[] urls = new URL[]{url};
// load compiled class
ClassLoader cl = new URLClassLoader(urls);
// create object of compiled class
Class<?> cls = Class.forName(fullMessageName, true, cl); // Crashes at this line
If I scroll down further in the errors it says:
Caused by: java.lang.ClassNotFoundException: com.google.protobuf.ExtensionRegistryLite
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
Any hints as to what may be causing this would be appreciated!

Related

Trying to add log4j in plugin type project. Error : java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator

I am trying to add Log4j.jar in plugin project for logging purpose. I add the log4j jar by using build path->add external jar. After that I am trying to run the plugin project I get error
java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator.
if I run the same code by using java main method it will working fine.
public HHLogger(Object className) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("ddMMYYYY");
System.setProperty("filename", df.format(LocalDate.now()));
PropertyConfigurator.configure(".\\resources\\log4j.properties");
logger = Logger.getLogger(className.getClass());
}
public static void main(String args[]) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("ddMMYYYY");
System.setProperty("filename", df.format(LocalDate.now()));
PropertyConfigurator.configure(".\\resources\\log4j.properties");
logger = Logger.getLogger(HHLogger.class);
logger.info(" 999 Welcom");
}
java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator
at com.americanexpress.connecthotelforgbt.utility.HHLogger.(HHLogger.java:22)
at com.americanexpress.connecthotelforgbt.parsers.OhhRqRsParser.(OhhRqRsParser.java:104)
at com.americanexpress.connecthotelforgbt.DataIntelliSense.upshellcommand(DataIntelliSense.java:322)
at com.americanexpress.connecthotelforgbt.listener.CommandModificationService.process(CommandModificationService.java:102)
at com.sabre.edge.cf.core.executors.PublicServiceExecutor.decide(PublicServiceExecutor.java:143)
at org.jbpm.graph.node.Decision.execute(Decision.java:85)
at org.jbpm.graph.def.Node.enter(Node.java:314)
at org.jbpm.graph.def.Transition.take(Transition.java:151)
at org.jbpm.graph.def.Node.leave(Node.java:389)
at org.jbpm.graph.node.StartState.leave(StartState.java:70)
at org.jbpm.graph.exe.Token.signal(Token.java:192)
at org.jbpm.graph.exe.Token.signal(Token.java:140)
at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:271)
at com.sabre.edge.cf.core.flow.JBPMFlowExecutor.execute(JBPMFlowExecutor.java:45)
at com.sabre.edge.cf.core.SRWRuntime.executeWorkflow(SRWRuntime.java:238)
at com.sabre.edge.cf.core.SRWRuntime.process(SRWRuntime.java:173)
at com.sabre.edge.cf.emu.bridge.EmulatorBridge.processServiceContext(EmulatorBridge.java:198)
at com.sabre.edge.cf.emu.bridge.EmulatorBridge.updateCommand(EmulatorBridge.java:87)
at com.sabre.stn.emulator.core.bridge.BridgeFilter.preSend(BridgeFilter.java:80)
at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.sendPreProcess(BasicEmulatorModel.java:3737)
at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.sendMessage(BasicEmulatorModel.java:3596)
at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.doEnter(BasicEmulatorModel.java:3516)
at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.enter(BasicEmulatorModel.java:1749)
at com.sabre.stn.emulator.basic.BasicEmulator.enter(BasicEmulator.java:1979)
at com.sabre.stn.emulator.core.EmuManager.emptyTheKeyBuffer(EmuManager.java:1132)
at com.sabre.stn.emulator.core.KeysToScreenThread.run(KeysToScreenThread.java:78)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.PropertyConfigurator
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 26 more
The error message is clear, it can not find the class file of PropertyConfigurator
make sure that the class file PropertyConfiguratoris in your classpath, or the same applies if it is in a jar file . it indicates, that PropertyConfigurator was found at compiletime but not at runtime. maybe you just have to add it to the classpath.
Please see this can help: How to solve java.lang.NoClassDefFoundError?
ps: if the two classes are on the same file, you can not do that, because both are public.

java.lang.ClassNotFoundException Error when trying to inject into running VM

I am trying to inject a .jar file in a running VM.
I've added tools.jar in the build path in eclipse, but when I try to run the injector, this error pops up. How should I add tools.jar to the project?
Full error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at src.testinjector.MainClass.main(MainClass.java:13)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
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
you may try:
Give the path to tools.jar instead of being dependent on JAVA_HOME.
Note: JAVA_HOME/path to jdk/bin/ should not have any space.
By default, the "tools.jar" classes are not loaded, your options are to either use a jdk that does load it, include tools.jar in your jar, or forcefully load it with the method below, (note: this might not work on certain jdk/jvm's)
private static void prepareAttach() throws NoSuchMethodException, MalformedURLException, InvocationTargetException, IllegalAccessException {
String binPath = System.getProperty("sun.boot.library.path");
// remove jre/bin, replace with lib
String libPath = binPath.substring(0, binPath.length() - 7) + "lib";
URLClassLoader loader = (URLClassLoader) [This Class].class.getClassLoader();
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURLMethod.setAccessible(true);
File toolsJar = new File(libPath + "/tools.jar");
if (!toolsJar.exists()) throw new RuntimeException(toolsJar.getAbsolutePath() + " does not exist");
addURLMethod.invoke(loader, new File(libPath + "/tools.jar").toURI().toURL());
}

Weka DiscriminantAnalysis NoClassDefFoundError

I'm trying to use MultiClassFLDA in discriminant analysis package but I always get an error on running the code and defining a new instance of the MultiClassFLDA class
Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Vector
at assignment2.face.tryLDA(face.java:141)
at assignment2.Assignment2.main(Assignment2.java:106)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Vector
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
It seems to be linked to some dynamic class loading in newer versions of Weka, presumably within the Weka Package Manager: that class is defined in the mtj.jar, which is bundled inside weka.jar. In that other question, an answer suggested to extract the mtj.jar and add it to your classpath.
As I didn't have this problem with other Filters, my guess is that MultiClassFLDA is not implemented correctly: I found out is that if you use another Filter before, that specific class will get loaded:
// Run a dummy Filter for correct initialization
Filter f = new Standardize();
f.setInputFormat(data);
Filter.useFilter(new Instances("", params, 0), f); // Dummy run on empty dataset
// Now run the MultiClassFLDA
f = new MultiClassFLDA();
f.setInputFormat(data);
data = Filter.useFilter(data, f);
N.B. that is a really ugly hack! I used it to be able to work. I'll edit my answer when I find the appropriate way to do it (other than extracting the jar from Weka itslef).

Java: Connecting to Quality Center using qcutils4j.jar

I have developed a runner module for my automation framework which will allow testers author and execute the tests using Eclipse IDE.
Now I am looking to add a module to connect to QC and upload my tests to the respective test plan. For this I am using qcutils.jar.
My Code:
public static void QCConnect()
{
File fUser = new File("lib");
File fNat = new File(fUser, "jacob-1.18-x64.dll");
// Set java library path at runtime
String javaPath = System.getProperty("java.library.path");
javaPath = javaPath+";"+fUser.getAbsolutePath()+";";
System.setProperty("java.library.path", javaPath);
String javaPath1 = System.getProperty("java.library.path");
// Load dll
System.load(fUser.getAbsolutePath()+"\\jacob-1.18-x64.dll");
IQcConnection conn = QcConnectionFactory.createConnection("https://<myqc>/qcbin");
conn.connect("user", "pass", "domain", "project");
TestClient tc = conn.getTestClient();
Test t = new Test();
t.setTestFolder(TestFolder.ROOT_FOLDER + "\\Demo");
t.setDescription("This is a QcTools4j Test");
t.setStatus("Design");
t.setName("myTest");
tc.saveTest(t)
}
Encountered Exception:
org.qctools4j.utils.DllLoader loadLibrary
SEVERE: DLL not found in the class path!
Exception in thread "main" org.qctools4j.exception.QcException: Can't get object clsid from progid
at org.qctools4j.clients.QcConnectionImpl.initConnection(Unknown Source)
at org.qctools4j.clients.QcConnectionImpl.<init>(Unknown Source)
at org.qctools4j.QcConnectionFactory.createConnection(Unknown Source)
at QCJavaConnect.main(QCJavaConnect.java:37)
Caused by: com.jacob.com.ComFailException: Can't get object clsid from progid
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at org.qctools4j.clients.QcConnectionImpl.initConnection(Unknown Source)
... 3 more
I am a looking for a solution on handling QC using java, I do not mind using any other java package.
Thanks in Advance!

Java URLClassLoader ClassNotFoundException

I have to write a .jar class loader in an assignment for school. I've found this code in another question but can't figure out why it wont work.
I've set the path to be an absolute path to make sure it references to the right file.
System.out.println("Loading game: " + name);
URL url = new URL("file:///home/<name>/Documents/School/thema2.3/batavus/batavus/gamemodules/TicTacToe.jar");
ClassLoader loader = new URLClassLoader(new URL[]{url});
Class<?> clazz = loader.loadClass("spatboard.game." + name);
Class<? extends Game> boardClass = clazz.asSubclass(Game.class);
Constructor<? extends Game> ctor = boardClass.getConstructor();
return ctor.newInstance(board);
The error I get is:
Loading game: TicTacToe
java.lang.ClassNotFoundException: spatboard.game.TicTacToe
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at spatbord.loader.GameLoader.loadModule(GameLoader.java:29)
at spatbord.model.Board.<init>(Board.java:51)
at spatbord.controller.GameController.onMatchStarted(GameController.java:157)
at spatbord.connection.Server.matchStarted(Server.java:428)
at spatbord.connection.Server.handleInput(Server.java:346)
at spatbord.connection.Server.run(Server.java:145)
at java.lang.Thread.run(Thread.java:745)
The package declaration in the TicTacToe is package spatbord.game;
The contents of the jar are:
spatbord
-> game
-> TicTacToe.class
What am I not seeing here?
Look at this stacktrace:
Loading game: TicTacToe
java.lang.ClassNotFoundException: spatboard.game.TicTacToe
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at spatbord.loader.GameLoader.loadModule(GameLoader.java:29)
at spatbord.model.Board.<init>(Board.java:51)
at spatbord.controller.GameController.onMatchStarted(GameController.java:157)
at spatbord.connection.Server.matchStarted(Server.java:428)
at spatbord.connection.Server.handleInput(Server.java:346)
at spatbord.connection.Server.run(Server.java:145)
at java.lang.Thread.run(Thread.java:745)
and the contents:
spatbord
-> game
-> TicTacToe.class
Specifically at this line:
java.lang.ClassNotFoundException: spatboard.game.TicTacToe
the JRE is expecting spatbord.game.TicTacToe, so this means you mispelled your package spatboard spatbord.
Please Use URLClassLoader instead of ClassLoader in 3rd line of code.
URLClassLoader loader = new URLClassLoader(new URL[]{url});
Let me know this worked or not.

Categories

Resources