I am writing an Eclipse plugin that supports automated testing like JUnit. I have a Launch Configuration Delegate that launches my Main class, which will run the tests on the class the user provides.
I want to programmatically show a custom View from my Eclipse plugin when I launch it with my Launch Configuration Delegate. I keep getting a NoClassDefFoundError for the AbstractUIPlugin class when I try to launch it even though I have included both org.eclipse.ui and org.eclipse.core.runtime in my plugin dependencies.
Stack Trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/ui/plugin/AbstractUIPlugin
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 eoo.thefamilycoder.specj.internal.launching.delegate.SpecJMain.main(SpecJMain.java:8)
Caused by: java.lang.ClassNotFoundException: org.eclipse.ui.plugin.AbstractUIPlugin
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
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SpecJ
Bundle-SymbolicName: eoo.thefamilycoder.specj;singleton:=true
Bundle-Version: 1.0.0.alpha
Bundle-Activator: eoo.thefamilycoder.specj.internal.Activator
Require-Bundle: org.eclipse.ui;bundle-version="3.105.0",
org.eclipse.core.runtime;bundle-version="3.9.0",
org.eclipse.jdt.launching;bundle-version="3.7.0",
org.eclipse.debug.core;bundle-version="3.8.0",
org.eclipse.jdt.core;bundle-version="3.9.1",
org.eclipse.debug.ui;bundle-version="3.9.0",
org.eclipse.jdt.ui;bundle-version="3.9.1",
org.eclipse.jdt.debug.ui;bundle-version="3.6.200"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Main class
import eoo.thefamilycoder.specj.internal.Activator;
public class SpecJMain {
public static void main(String[] args) {
Activator.getDefault().showView();
}
}
What is causing the error, and how can I fix it?
Edit: Adding launch code
Launch Configuration Delegate
public class SpecJLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate {
private static final int UNITS_OF_WORK = 4;
#Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch,
final IProgressMonitor monitor) throws CoreException {
final IProgressMonitor pm = monitor != null ? monitor : new NullProgressMonitor();
pm.beginTask(configuration.getName(), UNITS_OF_WORK);
if (pm.isCanceled()) return;
try {
preLaunchCheck(configuration, mode, pm);
if (pm.isCanceled()) return;
final VMRunnerConfiguration runConfig =
new VMRunnerConfigurationFactory().create(configuration, monitor, this);
if (pm.isCanceled()) return;
getVMRunner(configuration, mode).run(runConfig, launch, pm);
if (pm.isCanceled()) return;
} finally {
pm.done();
}
}
#Override
public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
final String[] initialClasspath = super.getClasspath(configuration);
final String pluginClasspath = new SpecJClasspathLocator().getClasspath();
System.out.println(pluginClasspath);
if (pluginClasspath == null) return initialClasspath;
final String[] classpath = new String[initialClasspath.length + 1];
classpath[0] = pluginClasspath;
System.arraycopy(initialClasspath, 0, classpath, 1, initialClasspath.length);
return classpath;
}
}
VMRunnerConfigurationFactory
public class VMRunnerConfigurationFactory {
public VMRunnerConfiguration create(final ILaunchConfiguration configuration, final IProgressMonitor monitor,
final AbstractJavaLaunchConfigurationDelegate delegate) throws CoreException {
final ExecutionArguments execArgs = new ExecutionArguments(delegate.getVMArguments(configuration), "");
// Activator.MAIN_TYPE_NAME is the main class above
final VMRunnerConfiguration runConfig = new VMRunnerConfiguration(Activator.MAIN_TYPE_NAME,
delegate.getClasspath(configuration));
runConfig.setBootClassPath(delegate.getBootpath(configuration));
runConfig.setEnvironment(delegate.getEnvironment(configuration));
runConfig.setProgramArguments(new ProgramArgumentsFactory().create(configuration, monitor));
runConfig.setVMArguments(execArgs.getVMArgumentsArray());
runConfig.setVMSpecificAttributesMap(delegate.getVMSpecificAttributesMap(configuration));
runConfig.setWorkingDirectory(getWorkingDirectoryName(delegate.verifyWorkingDirectory(configuration)));
return runConfig;
}
private String getWorkingDirectoryName(final File workingDir) throws CoreException {
return workingDir != null ? workingDir.getAbsolutePath() : null;
}
}
AbstractUIPlugin is in the org.eclipse.ui.workbench plug-in so you need that in your dependencies.
Edit.
Just noticed you are using a main method - this an Eclipse plugin you can't run this is as a normal Java program. You must either run it in an existing Eclipse RCP or create a RCP.
Edit 2
Your launch does nothing to properly initialize Eclipse to run a plugin. You must start an Eclipse app through the org.eclipse.equinox.launcher.Main entry point (normally via the eclipse executable). You must specify an application or product to run (like in the Run Configuration for an Eclipse Application).
Related
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?
This question already has answers here:
What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?
(15 answers)
Closed 6 years ago.
I am new at working with JPA and Hibernate so I have some problems with the typequery. I have a function that receives a string and the name of a "Departamento", and retrieves the object ("Carrera") that has that "Departamento" associated with it. In sqldeveloper I have no problem, but in typedquery it has become a bit of a hassle. I am sure that the syntax of my query is wrong, but I don't know how to fix. I would be grateful if someone could help me.
ClientePrueba.java:
public class ClientePrueba {
public static void main(String[] args) throws NamingException {
DepartamentosBeanRemote departamentosBean = (DepartamentosBeanRemote) InitialContext.doLookup("EjemploEJB/DepartamentosBean!com.servicios.DepartamentosBeanRemote");
MateriasBeanRemote materiasBean = (MateriasBeanRemote) InitialContext.doLookup("EjemploEJB/MateriasBean!com.servicios.MateriasBeanRemote");
CarrerasBeanRemote carrerasBean = (CarrerasBeanRemote) InitialContext.doLookup("EjemploEJB/CarrerasBean!com.servicios.CarrerasBeanRemote");
System.out.println("Obtengo todas las carreras del departamento MATEMATICAS");
List<Carrera> carreras = carrerasBean.obtenerPorDepartamento("MATEMATICAS");
for (Carrera car : carreras) {
System.out.println(car.getNombre());
}
}
}
CarrerasBean.java
/**
* Session Bean implementation class CarrerasBean
*/
#Stateless
public class CarrerasBean implements CarrerasBeanRemote {
#PersistenceContext
private EntityManager em;
/**
* Default constructor.
*/
public CarrerasBean() {
// TODO Auto-generated constructor stub
}
#Override
public List<Carrera> obtenerPorDepartamento(String departamento) {
TypedQuery<Carrera> query = em.createQuery("SELECT c FROM Carrera c WHERE c.departamento.nombre = :depto", Carrera.class)
.setParameter("depto", departamento);
return query.getResultList();
}
}
Error:
Exception in thread "main" javax.ejb.EJBException:
java.lang.ClassNotFoundException:
org.hibernate.collection.internal.PersistentBag at
org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:236)
at
org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at
org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy4.obtenerPorDepartamento(Unknown Source) at
com.cliente.ClientePrueba.main(ClientePrueba.java:130) Caused by:
java.lang.ClassNotFoundException:
org.hibernate.collection.internal.PersistentBag 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
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Unknown Source) at
org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)
at
org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:949)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1256)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at
org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1746)
at
org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1659)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadCollectionObject(RiverUnmarshaller.java:180)
at
org.jboss.marshalling.river.RiverUnmarshaller.readCollectionData(RiverUnmarshaller.java:777)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:653)
at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at
org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at
org.jboss.ejb.client.remoting.MethodInvocationResponseHandler$MethodInvocationResultProducer.getResult(MethodInvocationResponseHandler.java:103)
at
org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:276)
at
org.jboss.ejb.client.EJBObjectInterceptor.handleInvocationResult(EJBObjectInterceptor.java:64)
at
org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at
org.jboss.ejb.client.EJBHomeInterceptor.handleInvocationResult(EJBHomeInterceptor.java:88)
at
org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at
org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:46)
at
org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at
org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:129)
at
org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:265)
at
org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:453)
at
org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:202)
... 4 more
It looks like you dont have a hibernate jars in the client classpath.
I mean this dependency:
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
Check your client classpath and add this hibernate jars.
I want to run TestNG without using the "TestNG eclipse plugin" in a normal maven quickstart project.
Whatever I read from http://testng.org/doc/documentation-main.html#running-testng-programmatically & other sources, I got idea of using classes as:
MessageUtil.java
package com.mytests.testng;
public class MessageUtil {
private String message;
public MessageUtil(String message){
this.message = message;
}
public String printMessage(){
System.out.println(message);
return message;
}
}
TestNGExample.java
package com.mytests.testng;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestNGExample {
String message = "Hello World";
MessageUtil messageUtil = new MessageUtil(message);
#Test
public void testPrintMessage() {
Assert.assertEquals(message,messageUtil.printMessage());
}
}
App.java
package com.mytests.testng;
import org.testng.TestListenerAdapter;
import org.testng.TestNG;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
#SuppressWarnings("rawtypes")
Class[] testClasses = new Class[]{
TestNGExample.class
};
testNG.setTestClasses(testClasses);
testNG.addListener(tla);
testNG.run();
}
}
But here I am getting exceptions as:
Exception Box 1
Exception Box 2
Exception in Console
Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/ITestListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.testng.ITestListener
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)
... 7 more
I am not getting why there is a problem even though I don't get any compile time error. The TestNG dependency is successfully downloaded and helps in writing the code. But the class doesn't load on run time I guess. What can be done?
If not using any XML is causing an error, I can use it as well, but not the eclipse plugin for TestNG.
P.S.: I am new to TestNG and this is my first program
This issue is happening because at runtime, testng jar is not available in classpath. You can resolve this by using <scope>compile</scope> instead of <scope>test</scope> in your testng pom dependency.
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
I'm working though a book SWT/JFace IN ACTION by Manning Press.
When I added JFace, Eclipse for some reason could not find the main class though it is plainly present.
Here is the code
package com.swtjface.ChTwo;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class HelloSWT_JFace extends ApplicationWindow{
/**
* #param args
*/
public HelloSWT_JFace(){
super(null);
}
protected Control createContents(Composite parent){
Text helloText = new Text(parent, SWT.CENTER);
helloText.setText("Hello SWT and JFace!");
parent.pack();
return parent;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloSWT_JFace awin = new HelloSWT_JFace();
awin.setBlockOnOpen(true);
awin.open();
Display.getCurrent().dispose();
}
}
The reject message I get from Eclipse is...
Could not find the main class: com.swtjface.ChTwo.HelloSWT_JFace.
Program will exit.
Here is the exception...
java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
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)
Exception in thread "main"
You need at least 2 more jars to use JFace:
org.eclipse.equinox.common
org.eclipse.core.commands
See Using JFace outside the Eclipse platform for more details.
You need to add jar file for "org.eclipse.core.runtime.IProgressMonitor class"
Check this link.