I got something like this:
StudentBean.java
#PersistenceContext
EntityManager em;
#Override
public Boolean addStudent(Student s) {
try{
// Student s1 = new Student(10,"asd", "asd"); //this was for testing
em.persist(s);
em.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
Then I got the Student.java with this constructor:
public Student(Integer studentId, String firstName, String lastName) {
this();
this.studentId = studentId;
this.firstName = firstName;
this.lastName = lastName;
}
And I got a UTest.java class for testing the functions...
There I got this:
#Test public void testAddStudent() {
StudentBean sb = new StudentBean();
Student s1 = new Student(4, "Ognjen", "Car");
System.out.println(s1.toString()); //it does not print anything
Boolean s = sb.addStudent(s1);
assert (s == true);
// fail("Not yet implemented");
}
When I run the tests, it shows this error, and I simply cannot find an answer to it, pls help
java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:166)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:103)
at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:114)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:162)
... 9 more
Caused by: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.core.impl.ManagerImpl
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:166)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:103)
at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:62)
... 14 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:162)
... 17 more
Caused by: java.lang.NoClassDefFoundError: org/jboss/shrinkwrap/descriptor/api/Descriptor
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 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 java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.jboss.arquillian.core.impl.SecurityActions$1.run(SecurityActions.java:188)
at org.jboss.arquillian.core.impl.SecurityActions$1.run(SecurityActions.java:185)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.arquillian.core.impl.SecurityActions.getConstructor(SecurityActions.java:184)
at org.jboss.arquillian.core.impl.SecurityActions.newInstance(SecurityActions.java:158)
at org.jboss.arquillian.core.impl.Reflections.createInstance(Reflections.java:122)
at org.jboss.arquillian.core.impl.ManagerImpl.createExtensions(ManagerImpl.java:440)
at org.jboss.arquillian.core.impl.ManagerImpl.fireProcessing(ManagerImpl.java:375)
at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:100)
... 22 more
Caused by: java.lang.ClassNotFoundException: org.jboss.shrinkwrap.descriptor.api.Descriptor
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)
... 59 more
Here is also a picture
printed screen
Related
I tried to create a mock on a singleton class using powermockito, this singleton class extends JFrame, when I specify the class name in #PrepareForTest it gives an exception.
The Conditon I am trying to test
JComponent context = GVCScreenManager.getInstance().getSelectedComponent();
if( context instanceof GVCSerializable)
{
System.out.println(" third if"); //I need to go inside this if condition
GVCSerializable ser = (GVCSerializable) context;
GVCComponentState state = ser.getComponentState();
//some more method calls
}
Test case
#RunWith(PowerMockRunner.class)
#PrepareForTest({GVCScreenManager.class})//due to this I get illegal access exception as this class extends JFrame
class Myclass
{
#Test
public void testConsumeResult() {
GVCSerializable jc=Mockito.mock(GVCSerializable.class);
GVCScreenManager gvc=Mockito.mock(GVCScreenManager.class);
PowerMockito.mockStatic(GVCScreenManager.class);
Mockito.when(GVCScreenManager.getInstance()).thenReturn(gvc);
Mockito.when(gvc.getSelectedComponent()).thenReturn((JComponent) jc);
ResultHolder result=new AnnotationResultHolder(0);
annotationResultConsumer.consumeResult(result);
}
}
Stack trace
java.lang.IllegalAccessError: class javax.swing.JFrame cannot access its superinterface javax.swing.TransferHandler$HasGetTransferHandler
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:259)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:259)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(Unknown Source)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Unknown Source)
at sun.reflect.generics.tree.ClassTypeSignature.accept(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseSig(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseClassValue(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseClassArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(Unknown Source)
at java.lang.Class.createAnnotationData(Unknown Source)
at java.lang.Class.annotationData(Unknown Source)
at java.lang.Class.getAnnotation(Unknown Source)
at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:52)
at org.junit.internal.runners.TestClass.getAnnotatedMethods(TestClass.java:45)
at org.junit.internal.runners.MethodValidator.validateTestMethods(MethodValidator.java:71)
at org.junit.internal.runners.MethodValidator.validateStaticMethods(MethodValidator.java:44)
at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.validate(PowerMockJUnit44RunnerDelegateImpl.java:108)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:70)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.<init>(PowerMockJUnit47RunnerDelegateImpl.java:42)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl.<init>(PowerMockJUnit49RunnerDelegateImpl.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:149)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:39)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:218)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Please help me solve this problem.
include #PrepareForTest({TransferHandler.class,GVCScreenManager.class}) so we need to prepare for test of its superInterface Transferhandler
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
I created a webservice called calculator, an interface, an implementation class, and annotated it, and I was trying to create the service and the WSDL. Then I get the following Error. Not sure if it's a facet error or an error in the version of JAXWS from WAS 8.0? Tried to resolve it but couldn't find resources on the web as well.
** Here's the CODE**
//Interface:
package com.pp;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public interface Calculator {
#WebMethod
public int add(int var1, int var2);
}
//Implementation Class:
package com.pp;
import javax.jws.WebService;
#WebService(endpointInterface=" com.pp.Calculator")
public class CalculatorImpl implements Calculator {
#Override
public int add(int var1, int var2) {
// TODO Auto-generated method stub
return var1+var2;
}
}
ERROR:
Errors occurred during wsgen.
Errors occurred during wsgen.
error: compilation failed, errors should have been reported
Note: ap round: 1
Problem encountered during annotation processing;
see stacktrace below for more information.
com.ibm.jtc.jax.tools.ws.processor.modeler.ModelerException: [failed to localize] The endpointInterface class com.pp.Calculator could not be found()
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceAP.onError(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.getEndpointInterfaceDecl(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalImplementation(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.shouldProcessWebService(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.visitClassDeclaration(Unknown Source)
at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.accept(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceAP.buildModel(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceAP.process(Unknown Source)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(Unknown Source)
at com.sun.tools.apt.comp.Apt.main(Unknown Source)
at com.sun.tools.apt.main.JavaCompiler.compile(Unknown Source)
at com.sun.tools.apt.main.Main.compile(Unknown Source)
at com.sun.tools.apt.main.Main.compile(Unknown Source)
at com.sun.tools.apt.Main.processing(Unknown Source)
at com.sun.tools.apt.Main.process(Unknown Source)
at com.sun.tools.apt.Main.process(Unknown Source)
at com.ibm.jtc.jax.tools.ws.wscompile.WsgenTool.buildModel(Unknown Source)
at com.ibm.jtc.jax.tools.ws.wscompile.WsgenTool.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibm.ast.ws.jaxws.emitter.jdk6.jws22.command.WsGenCommand.execute(Unknown Source)
at com.ibm.ast.ws.jaxws.emitter.command.WsGenCommand.execute(Unknown Source)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.runCommand(Unknown Source)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.visitTop(Unknown Source)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.moveForwardToNextStop(Unknown Source)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager$6.run(Unknown Source)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(Unknown Source)
at org.eclipse.jface.operation.ModalContext.run(Unknown Source)
at org.eclipse.jface.wizard.WizardDialog.run(Unknown Source)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager.runForwardToNextStop(Unknown Source)
at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.runForwardToNextStop(Unknown Source)
at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.performFinish(Unknown Source)
at org.eclipse.wst.command.internal.env.ui.widgets.DynamicWizard.performFinish(Unknown Source)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(Unknown Source)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(Unknown Source)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Unknown Source)
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 org.eclipse.jface.window.Window.runEventLoop(Unknown Source)
at org.eclipse.jface.window.Window.open(Unknown Source)
at org.eclipse.wst.command.internal.env.ui.widgets.popup.DynamicPopupWizard.run(Unknown Source)
at org.eclipse.ui.internal.PluginAction.runWithEvent(Unknown Source)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(Unknown Source)
at org.eclipse.jface.action.ActionContributionItem.access$2(Unknown Source)
at org.eclipse.jface.action.ActionContributionItem$5.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 org.eclipse.ui.internal.Workbench.runEventLoop(Unknown Source)
at org.eclipse.ui.internal.Workbench.runUI(Unknown Source)
at org.eclipse.ui.internal.Workbench.access$4(Unknown Source)
at org.eclipse.ui.internal.Workbench$7.run(Unknown Source)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Unknown Source)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Unknown Source)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(Unknown Source)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(Unknown Source)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Unknown Source)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(Unknown Source)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(Unknown Source)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Unknown Source)
at org.eclipse.equinox.launcher.Main.basicRun(Unknown Source)
at org.eclipse.equinox.launcher.Main.run(Unknown Source)
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
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