ProGuard java and reflection - proguard

I obfuscate my jar application with proguard. When i run the program I am getting the following error:
java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflec
t.ParameterizedType
at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateGenericDAO.
<init>(Unknown Source)
at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateDBSynchroni
zerDAO.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateBridgeDAOFactory.instantiateDAO(Unknown Source)
at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateBridgeDAOFactory.getDBSynchronizerDAO(Unknown Source)
at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog.initSynchronizers(Unknown Source)
at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog.perform(Unknown Source)
at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog.access$1400(Unknown Source)
at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog$13$1.
run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
ERROR [Performer] (?:?) - java.lang.RuntimeException: Can not instantiate DAO: class gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateDBSynchronizerDAO
I use hibernate with annotations and dao pattern
the config of proguard is:
-dontnote
-verbose
-printmapping out.map
-keepattributes *Annotation*
-keepdirectories
# The main entry points.
-keep public class gr.analysis.synchronizer.ApplicationSupport {
public static void main(java.lang.String[]);
}
-keep class gr.analysis.synchronizer.**{*; }

The problem is proguard + java reflection, e.g. Class.forName("com.example.class").getInstance().
Also applicable for non-android java projects, see: Proguard and Reflection in Android

Related

How can I run multiple TestNG xmls via TestNG SuiteRunner class

Is it possible to run multiple to run multiple TestNG xmls via TestNG SuiteRunner class.
I created below Runner Class:
package com.util;
import java.util.ArrayList;
import java.util.List;
import org.testng.TestNG;
public class Runner {
public static void main(String[] args) {
TestNG runner = new TestNG();
List<String> suitefiles = new ArrayList<String>();
suitefiles.add("<path of Xml 1>");
suitefiles.add("<path of Xml 2>");
runner.setDefaultSuiteName("test");
runner.setTestSuites(suitefiles);
runner.run();
}
}
Following error occurred on executing above class file:
Exception in thread "main" org.testng.TestNGException: java.lang.NullPointerException
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:320)
at org.testng.TestNG.run(TestNG.java:1021)
at com.util.Runner.main(Runner.java:19)
Caused by: java.lang.NullPointerException
at org.testng.xml.TestNGContentHandler.endElement(TestNGContentHandler.java:712)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.testng.xml.XMLParser.parse(XMLParser.java:38)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
at org.testng.xml.Parser.parse(Parser.java:172)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:300)
... 2 more
Thanks and regards

java.lang.ClassNotFoundException: 'org.h2.jdbcx.JdbcDataSource'

I am trying to use HikariCP with h2 database. Here is my class responsible for sql
#Singleton
#Log
class SqlPersistence {
def config
{
def props = new Properties()
new File("build/resources/main/db.properties").withInputStream {
props.load(it)
}
log.info "Loaded properties: $props"
config = new HikariConfig(props)
}
#Lazy def ds = new HikariDataSource(config)
#Lazy def sql = new Sql(ds)
}
But when I try to run it using gradle task I get this error
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: 'org.h2.jdbcx.JdbcDataSource'
at com.zaxxer.hikari.util.UtilityElf.createInstance(UtilityElf.java:89)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:293)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:90)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:101)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:71)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorS
ite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:232)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:244)
at repository.persistence.SqlPersistence.getDs(SqlPersistence.groovy:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty
.java:73)
at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GtivePogoPropertySite.java:82)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:304)
at repository.persistence.SqlPersistence.getSql(SqlPersistence.groovy:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty
.java:73)
at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:8
2)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:304)
at repository.persistence.SqlPersistence.selectAll(SqlPersistence.groovy:42)
at repository.persistence.SqlPersistence$selectAll.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
at repository.BookRepository.findAll(BookRepository.groovy:11)
at repository.BookRepository$findAll.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114)
at service.BookService.findAll(BookService.groovy:13)
at service.BookService$findAll.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114)
at script.run(script.groovy:7)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:914)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:897)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:407)
at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
at script.main(script.groovy)
Caused by: java.lang.ClassNotFoundException: 'org.h2.jdbcx.JdbcDataSource'
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.zaxxer.hikari.util.UtilityElf.createInstance(UtilityElf.java:76)
... 65 more
My build.gradle looks like this
apply plugin: 'groovy'
repositories {
jcenter()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.3'
compile 'com.h2database:h2:1.4.191'
compile 'com.zaxxer:HikariCP:2.4.5'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'junit:junit:4.12'
testCompile 'cglib:cglib:3.2.1'
}
task runScript(dependsOn: 'compileJava', type: JavaExec) {
main = 'script'
classpath = sourceSets.main.runtimeClasspath + sourceSets.main.output
}
Why it's unable to find driver?
P.S. there is always some issue with using sql drivers...
It looks like your script is Java, but the snippet you posted is Groovy. So I think this is either an issue of how you call the Groovy part so that the H2 lib is not in Groovy classpath, because if I transform your code to Java and put it in script.java it works fine with your build.gradle. But it could also be a Groovy class loading problem. When I tried to access a database from a Gradle script (which essentially is also a Groovy script I had to do the following to get it working correctly:
// load JDBC drivers to the Groovy class loader to overcome java.sql.DriverManager quirks
Sql.classLoader.addURL new File('driver.jar').toURI().toURL()
Sql.withInstance('my:connection:string', 'user', 'pass', 'my.jdbc.DriverClass') {
it.execute 'select * from foo'
}
Maybe you need something similar.

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 .