Eclipse: Avoiding some dependencies to be include in JUnit runtime classpath - java

I am working under eclipse Luna:
Eclipse Java EE IDE for Web Developers.
Version: Luna Service Release 2 (4.4.2)
Build id: 20150219-0600
I have a project that has some unit tests and depends on other projects in my workspace as well as external dependencies resolved using maven.
The project builds ok, using as one of its dependencies
.m2/repository/asm/asm/3.1/asm-3.1.jar
The problem is that, when I try to run unit tests for the project (i.e. right mouse menu on the project's name and selecting "RunAs JUnit") it fails to run throwing the next exception:
May 27, 2015 2:06:10 PM com.sun.grizzly.http.servlet.ServletAdapter doService
SEVERE: service exception:
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at com.sun.grizzly.http.servlet.ServletAdapter.loadServlet(ServletAdapter.java:456)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:395)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:349)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
at com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:183)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:745)
I've been reviewing the JUnit runtime classpath using this line as the first in my code:
logger.trace("Execution classpath [" + System.getProperty("java.class.path") + "]");
And I've discovered that somehow, these two dependencies are in the classpath:
.m2/repository/org/ow2/asm/asm-debug-all/4.1/asm-debug-all-4.1.jar:
.m2/repository/org/ow2/asm/asm/4.0/asm-4.0.jar:
How can I get rid of them?
I've read a lot about going to the "Run Configuration" and delete the problematic dependency from the "Classpath" tab, but in my case, the "Classpath" tab only shows the next dependencies:
Bootstrap Entries
JRE System Library [JavaSE-1.7]
User Entries
MyProblematicProject
Could anyone tell me how to get rid of this annoying dependency or at least sheer a bit of light upon how does eclipse builds the JUnit runtime classpath and what chances are to modify it?
Thank you,
Juan Fra

Most likely something in the project's pom is pulling in those dependencies, transitively. Open the pom file in Eclipse's pom editor and you can use the Dependency Hierarchy tab to investigate how you're getting both asm versions. From there you can opt to exclude one or both that you don't want/need.

E-Riz, thanks for your reply. Effectively the dependencies are transitively pulled from other projects. They are already located en we have the next lines in our pom:
<dependency>
<groupId>websays</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-debug-all</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
</exclusions>
</dependency>
But, still having this pom config the execution classpath includes org.ow2.asm.asm and org.ow2.asm.asm-debug-all artifact.
Notice that I am always talking about the execution classpath, the build classpath works ok.

Related

Apache NiFi Custom NAR NoClassDefFoundError During Startup

I am attempting to install a custom NAR controller service bundle in my NiFi installation but get this error during startup. It acts like it can't find the RecordReaderFactory class from the nifi-record-serialization-service-api even though it is included as a dependency:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-service-api</artifactId>
<version>1.9.0</version>
</dependency>
Here is the project:
https://github.com/adamfisher/nifi-zonefile-record-serialization-service
Running maven install builds the NAR successfully. It's just when I startup NiFi, it gives this error. I'm pretty sure this is a maven POM configuration issue. I just don't work with Java too much and hoping someone can shed some light on why it is not finding the dependent class it needs?
nifi-app.log:
2019-03-02 15:22:15,245 INFO [main] org.apache.nifi.web.server.JettyServer Loading WAR: D:\nifi\NIFI-1~2.0\.\work\nar\framework\nifi-framework-nar-1.9.0.nar-unpacked\NAR-INF\bundled-dependencies\nifi-web-error-1.9.0.war with context path set to /
2019-03-02 15:22:15,261 INFO [main] org.apache.nifi.web.server.JettyServer Running in HTTP mode; host headers not restricted
2019-03-02 15:22:16,386 ERROR [main] org.apache.nifi.NiFi Failure to launch NiFi due to java.lang.NoClassDefFoundError: org/apache/nifi/serialization/RecordReaderFactory
java.lang.NoClassDefFoundError: org/apache/nifi/serialization/RecordReaderFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.loadExtensions(StandardExtensionDiscoveringManager.java:152)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:127)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:113)
at org.apache.nifi.web.server.JettyServer.start(JettyServer.java:925)
at org.apache.nifi.NiFi.<init>(NiFi.java:158)
at org.apache.nifi.NiFi.<init>(NiFi.java:72)
at org.apache.nifi.NiFi.main(NiFi.java:297)
Caused by: java.lang.ClassNotFoundException: org.apache.nifi.serialization.RecordReaderFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 common frames omitted
2019-03-02 15:22:16,387 INFO [Thread-1] org.apache.nifi.NiFi Initiating shutdown of Jetty web server...
2019-03-02 15:22:16,387 INFO [Thread-1] org.apache.nifi.NiFi Jetty web server shutdown completed (nicely or otherwise).
The NAR dependencies are used at runtime to create a chain of parent class loaders. So in your example you have
nifi-zonefile-record-serialization-service-nar -> (depends on)
nifi-zonefile-record-serialization-service-api-nar -> (depends on)
nifi-standard-services-api-nar
In the running application when it instantiates the instance of your record reader from your service NAR, it then needs to load the interface that implements which comes from your service API NAR, which then needs to load the RecordReader interface which comes from the standard services API NAR.
I have spent a lot of time on this. Finally, i have a working solution for me. My custom processor is using RecordReader for incoming stream. However, either compile or package failed in maven process. I had to customize pom.xml as following:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-service-api</artifactId>
<version>${nifi.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-services-nar</artifactId>
<version>${nifi.version}</version>
<type>nar</type>
</dependency>
I ended up needing to include the API NAR file as well even though it doesn't appear to be used anywhere. It's just a generic template class called MyService.
I have the same issue as described here and I managed to solved it including the dependencies at the nar module(nifi-base-nar) pom.xml
The dependency that you need to include is the following:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>${nifi.version}</version>
<type>nar</type>
</dependency>

NoClassDefFoundError org/apache/poi/ss/usermodel/Workbook

I am running a shell script which calls a java class to get some data from database and create an excel report with that data. I get the error Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook when the code hits the below line in my java class:
XSSFWorkbook workbook = new XSSFWorkbook ();
This is how I have defined the classpath:
CLASSPATH=${CLASSPATH}:<path-to-jars>/poi-2.5.1-final-20040804.jar
CLASSPATH=${CLASSPATH}:<path-to-jars>/poi-ooxml-3.11.jar
I verified that the jars have been downloaded(via gradle), so trying to understand what am I missing here. Can someone please help me with this?
Stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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.test.ExcelReportGenerator.writeExcel(ExcelReportGenerator.java:26)
at com.test.ReportRunner.createReport(ReportRunner.java:109)
at com.test.ReportRunner.main(ReportRunner.java:93)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
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)
... 15 more
As per this Apache POI FAQ entry, mixing POI jars between different versions is not supported and will break in all sorts of ways, such as the one you've found. Don't do it!
You need to be using your POI jars all from the same release. I'd suggest the latest version, available here (currently 3.15)
You should probably also review the components and their dependencies page, to ensure you've got all the required jars for your use of Apache POI. Well, or use a dependency management tool like Maven or Gradle to handle that for you!
I have downloaded the latest Apache POI binaries v3.17 here and it has all the required jars to create xlsx file and open with out any fuss.
Required jars are shown in below screenshots (refer to selected jars) FYR.
For apache poi to work, you need compatible jars.
I used these jars
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>openxml4j</artifactId>
<version>1.0-beta</version>
</dependency>
Delete the poi jar from your maven repository and download or build the project again.
poi 2.5.1 had no such package (and consequently a class) included (you can verify by unpacking the jar files as they are essentially zip archives). See the source.
Update the poi dependency to release 3. This also has the added benefit of matching the ooxml version.

TomEE throws An invalid Lifecycle transition

I'm doing a major refactor of a web application using the maven multi-module approach.
At the get-go there was only 1 module.
I've slowly been breaking out functionality and creating a dependency chain that the main module would depend on.
Other pertinent information worth mentioning:
We are using the following:
TomEE (Apache TomEE-JAXRS 1.5.1)
OpenEJB
Apache Maven
JDK 1.7.x
Currently my web-app is structured like this:
parent
pom.xml
|
common
pom.xml
|
persistence
pom.xml
|
export
pom.xml
|
main
pom.xml
So...
The common module's pom has NO other module dependencies.
The persistence module's pom has the following dependencies:
common
The export module's pom has the following dependencies:
common
persistence
The main module's pom has the following dependencies:
common
persistence
export
The parent module's pom specifies the REACTOR Build Order as follows:
common
persistence
export
main
Prior to the creation of the export module everything would build and deploy fine; however, now that I've broken out additional stuff from main and put it into the export module, the build is fine, but when I deploy the generated WAR file, the following stack-trace shows up upon start-up:
SEVERE: ContainerBase.removeChild: destroy:
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp]] in state [STARTING_PREP]
at org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:409)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:299)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1041)
at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1167)
at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1148)
at org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:635)
at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:1275)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:955)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:537)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:982)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:901)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:118)
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:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Oct 05, 2016 12:51:23 PM org.apache.tomee.catalina.TomcatWebAppBuilder startInternal
SEVERE: Unable to deploy collapsed ear in war
StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp] org.apache.openejb.OpenEJBException: Creating application failed:
C:\java\servers\apache-tomee-jaxrs-1.5.1\webapps\act-cde: Error building bean 'TaskDataAccessServices'. Exception: class java.lang.NoClassDefFoundError:
Could not initialize class com.myapp.cde.persistence.ejb.TaskDataAccessServices: Could not initialize class com.myapp.cde.persistence.ejb.TaskDataAccessServices
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:959)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:537)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:982)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:901)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:118)
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:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.openejb.OpenEJBException: Error building bean 'TaskDataAccessServices'. Exception: class java.lang.NoClassDefFoundError:
Could not initialize class
com.myapp.cde.persistence.ejb.TaskDataAccessServices: Could not
initialize class
com.myapp.cde.persistence.ejb.TaskDataAccessServices
at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:81)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:713)
... 18 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.myapp.cde.persistence.ejb.TaskDataAccessServices
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.load(EnterpriseBeanBuilder.java:425)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.loadClass(EnterpriseBeanBuilder.java:405)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.build(EnterpriseBeanBuilder.java:81)
at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:66)
... 19 more
Notice the TaskDataAccessServices mentioned in the stack-trace. This class is located in the persistence module. What's weird is that it's NOT used at all in the export module, which I've just created.
Question of the day: What's the best approach at debugging this issue?
I've thought about backing out changes one by one and putting classes back into the main module --- but this could take awhile ...
Wondering if there was a silver bullet approach to resolving this?
Cheers.
I'd open up your artifact and see if com.myapp.cde.persistence.ejb.TaskDataAccessServices is actually present in it.
That's what this stack trace is telling you:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.myapp.cde.persistence.ejb.TaskDataAccessServices
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.load(EnterpriseBeanBuilder.java:425)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.loadClass(EnterpriseBeanBuilder.java:405)
at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.build(EnterpriseBeanBuilder.java:81)
at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:66)
... 19 more
In the main pom.xml file, I had the following <dependency>:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.8.3</version>
</dependency>
In the export pom.xml file, I had the following <dependency>:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
Little did I know that the ehcache had it's own dependency of slf4j.
Changing the ehcache <dependency> to the following fixed things up for me:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.8.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Figuring this out required me to back things out one at a time until things stopped breaking.
Lesson learned here: commit small, commit often.

Getting java.lang.ClassNotFoundException:MalformedPatternException

While trying to marshal the java object to xml i am getting below exception .
java.lang.ClassNotFoundException: org.apache.oro.text.regex.MalformedPatternException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.castor.xml.AbstractInternalContext.getRegExpEvaluator(AbstractInternalContext.java:325)
at org.exolab.castor.xml.validators.PatternValidator.initEvaluator(PatternValidator.java:262)
at org.exolab.castor.xml.validators.PatternValidator.validate(PatternValidator.java:200)
at org.exolab.castor.xml.validators.StringValidator.validate(StringValidator.java:302)
at org.exolab.castor.xml.validators.StringValidator.validate(StringValidator.java:340)
at org.exolab.castor.xml.FieldValidator.validateInstance(FieldValidator.java:324)
at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:271)
at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1072)
at org.exolab.castor.xml.Validator.validate(Validator.java:135)
at org.exolab.castor.xml.Marshaller.validate(Marshaller.java:2594)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:826)
at in.mywebapp.util.XMLUnmarshaller.getStatusRequestParam(XMLUnmarshaller.java:266)
Not sure which jar is missing .
you are probably missing oro.jar. You can add maven dependency
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
<version>2.0.8</version>
</dependency>
or download the jar from maven repository
Please make sure oro jar file is in classpath. It is not there. So, class loading is failing

main class exception when running db2triples for the first time

I'm trying to use db2triples for the first time, which is a java / maven project.
I got information about it from its github page.
So far, I have performed the following steps:
cd /programs/db2triples-master
vim pom.xml and added the db2triples dependency
mvn compile
mvn package
mvn dependency:copy-dependencies
java -cp target/dependency/*.jar:target/db2triples-1.0.3-SNAPSHOT.jar net.antidot.semantic.rdf.rdb2rdf.main.Db2triples
And I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
at java.lang.Class.getMethod0(Class.java:3010)
at java.lang.Class.getMethod(Class.java:1776)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
After googling around, this may be a classpath error, but I'm not sure. What needs to be done in order to run this application?
The error means that when you run db2triples, it can't find a dependency that is needed.
One way to resolve this problem is to add the required dependencies to your class path. Is the apache commons cli jar actually sitting in target/dependencies?
Another way to resolve this is to build a jar that has all the dependencies embedded. The assembly plugin as a jar-with-dependencies descriptor. Add this to your <build><plugins> section in your pom.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorId>jar-with-dependencies</descriptorId>
</configuration>
</plugin>
To build it mvn assembly:assembly.
You should have another jar sitting in targets named something like db2triples-<version>-jar-with-dependencies.jar. Then to run the application, you just need to run java -cp dbp2triples-<version>-jar-with-dependencies.jar net.antidot.semantic.rdf.rdb2rdf.main.Db2triples
According to your linked github page, you should get the required dependencies
Needed dependency
OpenRdf Sesame > 2.6.x - http://www.openrdf.org/
Commons-cli > 1.2 - http://commons.apache.org/cli/
Commons-logging > 1.1.1 - http://commons.apache.org/logging/
Or, if you're using maven, add db2triples as a dependency to your pom
<dependency>
<groupId>net.antidot</groupId>
<artifactId>db2triples</artifactId>
</dependency>

Categories