Missing Permissions manifest attribute in main jar - nullpointerexception

I am trying to run an applet in html, but keep getting this NullPointerException.
Below is the stacktrace,
CacheEntry[file:/C:/Users/User/workspace/SearchAlgorithms/bin/Main.jar]: updateAvailable=false,lastModified=Fri Apr 24 15:09:46 IST 2015,length=10095
Missing Permissions manifest attribute in main jar: file:/C:/Users/User/workspace/SearchAlgorithms/bin/Main.jar
java.io.FileNotFoundException: dataProduct.csv (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at Main.init(Main.java:39)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.io.FileNotFoundException: dataLocation.csv (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at Main.init(Main.java:45)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Java Plug-in 10.79.2.15
Using JRE version 1.7.0_79-b15 Java HotSpot(TM) Client VM
User home directory = C:\Users\User
Things that I have tried:
Signing the jar file
Including the accesscontrol.dopriviledge,
try {
FileInputStream fis = AccessController.doPrivileged(
new PrivilegedExceptionAction<FileInputStream>() {
public FileInputStream run() throws FileNotFoundException {
return new FileInputStream("someFile");
}
});
} catch (PrivilegedActionException e) {
// e.getException() should be an instance of FileNotFoundException,
// as only "checked" exceptions will be "wrapped" in a
// PrivilegedActionException.
throw (FileNotFoundException) e.getException();
}
The applet runs perfectly on the applet viewer. But embedding in html, gives the NullPointerException.
Please Help.

Related

How to attach bytebuddy agent when target application load classes from uRLConnection.getInputStream

I made a java agent with bytebuddy. It works well untill target application load classes form uRLConnection.getInputStream. The target app works well without attachment the agent, but shows exception [java.lang.ClassNotFoundException] when the agent attached.
this is app's classloading line.
return this.getClass().getClassLoader().loadClass(string) //string points the name of a byte array.
In the application, the classes is provided in the form of byte array from the uRLConnection.getInputStream at runtime and the application loads those at runtime.
The eclipst stacktrace:
[Byte Buddy] COMPLETE client [app.m#7dc3712, null, loaded=false]
Exception in thread "main" java.lang.NoClassDefFoundError: kh
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at app.m.loadClass(m.java:22)
at java.lang.ClassLoader.loadClass(Unknown Source)
at app.appletviewer.b(appletviewer.java:1176)
at app.appletviewer.a(appletviewer.java:454)
at Launcher.main(Launcher.java:43)
Caused by: java.lang.ClassNotFoundException: kh
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 app.u.loadClass(u.java:79)
at java.lang.ClassLoader.findSystemClass(Unknown Source)
at app.m.loadClass(m.java:30)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
My agent is:
try {
new AgentBuilder.Default()
.with(new AgentBuilder.InitializationStrategy.SelfInjection.Eager())
.with(AgentBuilder.Listener.StreamWriting.toSystemError())
.type((ElementMatchers.any()))
.transform((builder, typeDescription, classLoader, module) -> builder
.method(ElementMatchers.any())
.intercept(Advice.to(MyAdviser.class))
).installOn(instrumentation);
} catch (Exception e) {
return;
}
I also tried
.transform(new AgentBuilder.Transformer.ForAdvice()
.include(MyAdviser.class.getClassLoader())
.advice(ElementMatchers.any(), MyAdviser.class.getName()))
But it doesn't seem to be attached.
I think your problem might be something else here. Try the second form of advice which avoids class loading where a class loading of a system class in an too ealry stage is probably is your problem in the application of loaded advice. Set an .ignore(none()) matcher for the instrumentation to make the second approach work as boot strap classes like URLConnection are not by instrumented by Byte Buddy in the default configuration.

Facing issue with java.lang.NoClassDefFoundError: org/apache/velocity/context/Context

I'm a new learner velocity. I am trying to display the template in HTML format by writing a servlet for that. The following is my servlet code
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
VelocityEngine velocityEngine = new VelocityEngine();
try {
velocityEngine.init();
Template template = velocityEngine.getTemplate("./src/Menu.txt");
VelocityContext context = new VelocityContext();
context.put( "special-1", "./src/special-1.txt" );
context.put( "special-2", "./src/special-2.txt" );
context.put( "special-3", "./src/special-3.txt" );
StringWriter writer = new StringWriter();
template.merge(context, writer);
out.println(writer);
} catch (Exception e) {
e.printStackTrace();
}
}
And following is the stack trace im getting...
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 7 more
Caused by: java.lang.NoClassDefFoundError: org/apache/velocity/context/Context
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:263)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:142)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.velocity.context.Context
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 21 more
Can anybody help me out?
You need to add the velocity-version.jar to your server classpath, you can put it in the lib folder of your tomcat server, or you can put this jar in the WEB-INF/lib folder of your project.
Download velocity-1.7 jar and add in to eclipse Deployment Assembly then restart the server.

beans.xml file and java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

I have very strange exception after starting using beans.xml file in our EJB and jar files.
We use JBoss7.1.1 release.
Our application is packaged as ear file.
It was deployed and works correctly earlier.
There is some Module1 EJB component. Now we use #Inject annotation for some beans in Module1 and therefore added META-INF/beans.xml.
Another EJB component Module2 uses EJB from Module1 like:
#EJB
private IOmistajaFinderLocal omistajaFinder;
But now application cannot be deployed on JBoss. There following exception:
java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)
at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)
at javax.naming.InitialContext.createSubcontext(Unknown Source)
at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)
at com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:267)
at com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:273)
at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:192)
at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)
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.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:46)
at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:322)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_09]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_09]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_09]
Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
at
org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)
at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)
at javax.naming.InitialContext.createSubcontext(Unknown Source)
at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)
at com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:267)
at com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:273)
at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:192)
at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)
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.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:46)
at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:322)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:48)
at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:322)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
... 5 more
08:55:05,315 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"Helle.ear\".WeldService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"Helle.ear\".WeldService: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)
at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)
at javax.naming.InitialContext.createSubcontext(Unknown Source)
at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)
at com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:267)
at com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:273)
at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:192)
at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)
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.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:46)
at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:322)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"}}}}
Both Module1 and Module2 are included in application.xml file and generated ear file.
Deleting beans.xml resolves the deploying process but in this case we can not use #Injection annotation.
What is the problem and how can I resolve it? Thank you.
This is a known issue when using jersey. Try to add below option to your jvm, which will fix your issue. If you are running the jboss server from eclipse then add to the server runtime configuration. If you are starting the jboss from command prompt using standalone.bat then add the below option to standalone.conf.bat. Similarly if you are using *Nix then add to standalone.conf.
set "JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"
For use in eclipse (run and debug), open server properties, launch configuration properties and set the VM arguments:
-Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
I am able to manage this. Add a patch in naming jar. Just change org.jboss.as.naming.service.NamingStoreService -> readOnly = true
Full java class -
public class NamingStoreService implements Service<ServiceBasedNamingStore> {
private final boolean readOnly = false;
private volatile ServiceBasedNamingStore store;
public NamingStoreService() {
this(false);
System.out.println("Setting readOnly "+readOnly);
}
public NamingStoreService(boolean readOnly) {
System.out.println("Setting readOnly "+readOnly);
}
/**
* Creates the naming store if not provided by the constructor.
*
* #param context The start context
* #throws StartException If any problems occur creating the context
*/
public void start(final StartContext context) throws StartException {
if(store == null) {
final ServiceRegistry serviceRegistry = context.getController().getServiceContainer();
final ServiceName serviceNameBase = context.getController().getName();
final ServiceTarget serviceTarget = context.getChildTarget();
store = readOnly ? new ServiceBasedNamingStore(serviceRegistry, serviceNameBase) : new WritableServiceBasedNamingStore(serviceRegistry, serviceNameBase, serviceTarget);
}
}
/**
* Destroys the naming store.
*
* #param context The stop context
*/
public void stop(StopContext context) {
if(store != null) {
try {
store.close();
store = null;
} catch (NamingException e) {
throw MESSAGES.failedToDestroyRootContext(e);
}
}
}
/**
* Get the context value.
*
* #return The naming store
* #throws IllegalStateException
*/
public ServiceBasedNamingStore getValue() throws IllegalStateException {
return store;
}
}

JUnit test can't find class in different folder

i'd like to run my tests from console so i wrote a small program(klasse.java):
package nl.user;
public class klasse {
public static int sum(int a,int b){
return a+b;
}
}
and a test(mainTest.java):
package nl.user.TestPackage;
import static org.junit.Assert.*;
import nl.user.klasse;
import org.junit.Test;
public class mainTest2 {
#Test
public void test() {
assertEquals(10, klasse.sum(7,3));
}
}
everything works fine as long as both .class files are in the same folder. But in all my other programs my programs and tests are in different folders. As you see the program is in the ".../nl/user" direction and the test is in a subfolder ".../nl/user/TestPackage".
if i run the testfile with the following .bat file:
set CLASSPATH=,;%CLASSPATH%;C:\Users\myname\Downloads\eclipse-SDK-4.2-win32-x86_64\eclipse\plugins\org.junit_4.10.0.v4_10_0_v20120426-0900\junit.jar;C:\Users\myname\workspace\JUnitTest\bin\nl\user;C:\Users\myname\workspace\JUnitTest\bin\nl\user\TestPackage;C:\Users\nlagemann\workspace\JUnitTest\src\nl\user;C:\Users\nlagemann\workspace\JUnitTest\tests\nl\user\TestPackage
java org.junit.runner.JUnitCore mainTest2
pause
(yes, not all of the CLASSPATH is needed)
i get:
Exception in thread "main" java.lang.NoClassDefFoundError: mainTest2 (wrong name
: nl/user/TestPackage/mainTest2)
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.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:89)
at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:53)
at org.junit.runner.JUnitCore.main(JUnitCore.java:45)
i think i have to do sth. with the CLASSPATH but i can't figuure out what :/

Getting Exception while trying to execute axis2 service client

I am trying to create a sample axis2 ServiceClient. It is throwing below error
org.apache.axiom.om.OMException: No meta factory found for feature 'default'; this usually means that axiom-impl.jar is not in the classpath
at org.apache.axiom.om.OMAbstractFactory.getMetaFactory(OMAbstractFactory.java:170)
at org.apache.axiom.om.OMAbstractFactory.getMetaFactory(OMAbstractFactory.java:135)
at org.apache.axiom.om.OMAbstractFactory.getOMFactory(OMAbstractFactory.java:184)
at org.apache.axis2.description.AxisDescription.<init>(AxisDescription.java:68)
at org.apache.axis2.engine.AxisConfiguration.<init>(AxisConfiguration.java:148)
at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:639)
at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:68)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:184)
at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:150)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:143)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:244)
at org.apache.axis2.samples.tu.client.TUrlSOAPClient.addUrl(TUrlSOAPClient.java:46)
at org.apache.axis2.samples.tu.client.TUrlClient.actionPerformed(TUrlClient.java:69)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
The axiom-impl.jar is present in the classpath. Below is the code snippet. In the console I can see that sysout statement "Entered" is displayed, after that its throwing error at ServiceClient object creation. Have tried using different versions of the axiom-impl.jar (1.2.12, 1.2.13, 1.2.7, 1.2.5) but still getting the same error.
public static String testFunction(String testData) throws Exception {
System.out.println("Entered");
//Create a service client
ServiceClient client = new ServiceClient();
System.out.println("Before calling set end point");
//Set the endpoint address
client.getOptions().setTo(new EndpointReference(EPR));
System.out.println("After calling set end point");
System.out.println("getPayload(url)="+getPayload(testData));
//Make the reqest and get the response
OMElement resp = client.sendReceive(getPayload(testData));
//Extract the URL and return
return extractUrl(resp);
}
I had the same error but finally got solved by using axiom-api 1.2.12 and axiom-impl 1.2.12 after long struggle.
Solved this by replacing all the three individual axiom jars( axiom-impl-1.2.13.jar, axiom-dom-1.2.13.jar and axiom-api-1.2.13.jar) by just axiom.jar.
when I use above jar I got another error.
java.lang.ClassCastException: java.lang.ClassCastException: org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory
I had to increase version to 1.2.14 of each jar
I had the same error. I did replace the individual axiom jars( axiom-impl-1.2.13.jar, axiom-dom-1.2.13.jar and axiom-api-1.2.13.jar) by just axiom.jar, but the error still happening.
The root cause of the error was the location of META-INF/axiom.xml file. In my case, the XMLParser of the J2EE server container can not open the axion.xml file when it be localized within a jar file.
I had to copy META-INF/axiom.xml into WEB-INF/classes/META-INF/axiom.xml .