Getting Exception in Data Driven Framework Scenario while using Apache POI - java

Getting Exception in Data Driven Framework Scenario while using Apache POI
I am getting the exception when I execute a scenario using datadriven framework with Apache POI. I am not sure if its a version issue, can anyone please take a look at the exception below to see what is causing this issue and any resolution. Let me know if need anymore details.
Versions:
Eclipse: Oxygen.3a Release (4.7.3a)
WebDriver: 3.4.0
POI: 3.17
As a work around I have added dom4j-1.6.jar and xmlbeans-xmlpublic-2.3.0.jar, which dint seem to solve the issue.
EXEPTION:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/impl/common/SystemCache
at org.apache.poi.POIXMLDocument.init(POIXMLDocument.java:76)
at org.apache.poi.POIXMLDocument.<init>(POIXMLDocument.java:62)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:295)
at Carpet_Utility.ExcelUtils.setExcelfile(ExcelUtils.java:24)
at Carpet_Main.Main1.main(Main1.java:19)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.impl.common.SystemCache
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)
... 5 more
Exception Screenshot

I think you have downloaded the wrong jar xmlbeans-xmlpublic-2.3.0.jar.
You have to download the xmlbeans-x.x.x.jar.
If you are using maven, then add this dependency in the pom.xml :
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
or if you want to use jar, then download from here : mvnrepository
The screenshot of the org.apache.xmlbeans.impl.common.SystemCache class :

As i have already mentioned in a comments section that for apache poi functionality you have to add xmlbeans-2.3.0.jar dependency as well.
If you are using maven then you have to add this dependency in pom.xml along with dom4j-1.6.jar.
If you are using through jar dependency then you have to download this jar and then have to include in your project.

Related

JDK8: "java.lang.NoClassDefFoundError: javax/xml/ws/Service"

Fairly new to Webservices, have done some research and generated client stubs for a third party WSDL using JAX-WS RI (wsimport tool). JDK 8 is being used. Using generated Stubs, web service client is written to invoke the WSDL operations. Maven Build is successful but while testing it, getting "java.lang.NoClassDefFoundError: javax/xml/ws/Service".
Here is the Web service client. Tried to refer many resources for NoClassDefFoundError as well, but nothing actually worked. While debugging understood its failing in line-11 below. How to fix this NoClassDefFoundError, please Help?
line-11: ServiceWS service = new ServiceWS(); //#WebServiceClient
line-12: ServiceWSSoap stubWS = service.getServiceWSSoap(); //where ServiceWSSoap is #WebService and getServiceWSSoap() is #WebEndpoint
Here is the Stack trace
java.lang.NoClassDefFoundError: javax/xml/ws/Service
at package1.ProjectClient.getStub(ProjectClient.java:11)
at package.Project.<init>(Project.java:55)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.base/java.lang.Class.newInstance(Unknown Source)
at package.SubClass.getInstance(SubClass.java:1284)
at package.SubClass.getCall(SubClass.java:635)
at package.SubClass.execute(SubClass.java:317)
at package.MainClass.run(MainClass.java:1216)
at package.MainClass.execute(MainClass.java:759)
at package.ServerClass.b(ServerClass.java)
at package.ServerClass.run(ServerClass.java)
at java.base/java.lang.Thread.run(Unknown Source)
I have included jaxws-api dependency in my pom.xml, but still no luck
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
Research links:
1) Java Webservice Client (Best way)
2) https://mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
3) https://mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
You have included only API classes.
Your project needs also some Implementation classes (artifact).
One of possible implementations is jaxws-ri:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.1</version>
</dependency>
Thanks for your response Volo Myhal. I have already included jaxws-rt dependency as well. But still I keep getting NoClassDefFoundError.
This issue is resolved after manually adding the required jars into our local server path from the .m2 folder

From command line - java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

OK. I know there are other questions like this one out there and this is not the first time that slf4j has kicked my butt. However, I have looked at my PATH in Environment Variables and below are the two slf4j jar files included in my PATH as well as my project dependencies.
C:\Users\pdl\.m2\repository\org\slf4j\slf4j-api\1.7.13\slf4j-api-1.7.13.jar
C:\Users\pdl\.m2\repository\org\slf4j\slf4j-simple\1.7.13\slf4j-simple-1.7.13.jar
This is what is in my pom file:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.7.13</version>
</dependency>
Other applications we are running contain slf4j jar dependencies in the IDE but they are not listed in the pom file. I am so confused about where to put what that I can't see straight.
This is what the application dependencies look like:
I can run the application from the IDE (Netbeans) but I get the following error when I try to run from command prompt.
C:\Users\pdl\Projects\WeatherTestDrive>java -cp WeatherApp.jar;WeatherOpenWeatherMap.jar;WeatherClient.jar com.a2i.weatherclient.Client
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.a2i.weatherclient.Client.<clinit>(Client.java:22)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 1 more
Adding slf4j in my VM classpath and I still get the error.
C:\Users\pdl\Projects\WeatherTestDrive>java -cp WeatherApp.jar;WeatherOpenWeatherMap.jar;WeatherClient.jar;C:\Users\pdl\.m2\repository\org\slf4j\slf4j-api\1.7.13\slf4j-api-1.7.13.jar;C:\Users\pdl\.m2\repository\org\slf4j\slf4j-simple\1.7.13\slf4j-simple-1.7.13.jar com.a2i.weatherclient.Client
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.a2i.weatherclient.Client.<clinit>(Client.java:22)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 1 more
Can somebody please help me figure out what I am doing wrong?
Should I be adding slf4j-api to my dependencies instead of slf4j-exe? Or even something else?
I guess whichever one I use, I should add it to my VM classpath.
Does it even need to be in my pom file?
------------------------------ EDIT ----------------------------------
I created a simple HelloWorld app to log my name. As soon as I added the Logger to my Hello class it was highlighted in red, so I added the slf4j-simple to my dependencies and slf4j-api came with it. But when I opened the pom file only the slf4j-simple was added:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.13</version>
</dependency>
When I run from the IDE, everything works well. But when I run from command line I still get the error:
C:\Users\pdl\Projects\HelloWorld\target>java -cp HelloWorld-1.0-SNAPSHOT.jar;C:\Users\pdl\.m2\repository\org\slf4j\slf4j-simple\1.7.13\slf4j-simple-1.7.13.jar com.a2i.helloworld.Hello
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.a2i.helloworld.Hello.<clinit>(Hello.java:17)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 1 more
Where's slf4j in your VM classpath? Try running as follows:
java -cp WeatherApp.jar;WeatherOpenWeatherMap.jar;WeatherClient.jar;C:\Users\pdl\.m2\repository\org\slf4j\slf4j-api\1.7.13\slf4j-api-1.7.13.jar;C:\Users\pdl\.m2\repository\org\slf4j\slf4j-simple\1.7.13\slf4j-simple-1.7.13.jar com.a2i.weatherclient.Client
You're missing slf4j from your runtime. Hope that helps.
Maven, and thus the pom-file, are intended to build the classpath for you.
So yes, all depedencies you like to use should be in your pom file.
Regarding slf4j:
slf4j-api is a dependency that only defines an api (or interface). To make it work you also have to add an implementation. See here for explanation. So you have to add at least one more dependency. For example:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
Regarding slf4j-ext, i am quite sure you dont need it to simply log. Maybe you have more elaborate use cases.
To start your application from command line you have to run java with the -cp argument. The classpath is a list all used classes or archives containing classes. For applications with a lot of dependencies it can become quiet cumbersome to build it manually.
Use mvn dependency:build-classpath to let maven build this big string of jar-paths for you.
This concerns Java SE projects built in IntelliJ where slf4j - or any other library for that matter - is included (i.e. slf4j-api-1.7.26.jar => The API & slf4j-simple-1.7.26.jar => the API implementation)...
Step #1:
create folder \libs in project root and place the two JARs in there click to see project structure
step #2:
Build code and make sure that the Logger is working properly inside the IDE.
step #3:
Launch cmd and navigate using cd command inside the .\out directory up until the packages
of the main (check 1st line of Main.java). i.e.
cd C:\Users.....\out...\testcp
step #4
Do right click on sjf4j-api jar and copy path (path#1) &
Do right click on sjf4j-simple jar and copy path (path#2) &
Do right click on Main.class and copy path (path#3. SOS: EXCLUDE THE Main.class part).
Now, run java command with -cp flag as:
java -cp path#1;path#2;path#3; org.me.Main
That's it
Note: Eclipse users do not run into this problem since this is taken care of by using the build path utility.

Java: java.lang.NoClassDefFoundError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager

I created a webservice using servlet and Tomcat 6.0.
I created a java project in eclipse to call that webservice using HTTP.
I added the following jar files
1. httpcore-4.0
2. httpclient-4.0
but while running the project im getting the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.<init>(ThreadSafeClientConnManager.java:75)
at WSCall.HttpUtilities.GetServerResponse(HttpUtilities.java:52)
at WSCall.ServiceCall.main(ServiceCall.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
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)
... 3 more
Please help me to find the solution.
You still have to add common-logging dependency under your classpath. However, you may continue encounter other simaliar Exceptions due to lack other dependency. I suggest you use maven to manage the dependency so that you don't have to mannualy add dependencies to your classpath.
It seems your project doesn't contain the Apache Commons Logging library. Adding it to your classpath should do the trick.
This is caused by the missing of commons-logging.jar.To fix it, download the commons logging library and add it to your project.

Java: NoClassDefFoundError using Apache Commons CLI 1.2

I am using the Apache Commons CLI 1.2 to parse command line arguments in Java. I had run into the NoClassDefFoundError when trying to run my java class but solved it by fixing the class-paths.
Now I have the same exception but in regards to the actual commons-cli classes as is shown below:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cl i/CommandLineParser Caused by:
java.lang.ClassNotFoundException: org.apache.commons.cli.CommandLineP arser
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) Could not find the main class: com.amirsys.score.api.script.CMDContentPusher.
The only thing I could think of is to set the class path to the commons-cli jar but that did not work. I haven't been able to find a solution to fixing the NoClassDefFoundError for imported classes. I thought these were compiled into the .class files?
Commons CLI is not in the classpath at runtime. If you struggle to get the classpath right you can try to package your application as a single big jar file containing all its dependencies, including Commons CLI. There are many tools to achieve that (jarjar, onejar, Maven shade plugin...)

Java/eclipse/hibernate

I'm a .net dev, usually do this using nhibernate and can work with that fine. I'm doing a project which needs to be written in Java and have the following issue:
All I have so far is a blank java project setup in eclipse. I have C:\work\lib\java\cp\hibernate3.jar in the Referenced Libraries node in the package explorer.
in my code (main) i'm doing this
Configuration config = new Configuration().
setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect").
setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:RefenceDb").
setProperty("hibernate.connection.username", "sa").
setProperty("hibernate.connection.password", "").
setProperty("hibernate.connection.pool_size", "1").
setProperty("hibernate.connection.autocommit", "true").
setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider").
setProperty("hibernate.hbm2ddl.auto", "create-drop").
setProperty("hibernate.show_sql", "true").
addClass(Boy.class);
and in the consol i have:
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at ReferenceApplication.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 1 more
any ideas?
the path C:\work\lib\java\cp\ is in the classpath
w://
While the other answers here referencing dom4j are correct, you will soon find there a dozen or so other dependencies.
Starting from total scratch is a noble pursuit, but I would actually recommend giving yourself a head start by installing Maven (for dependency management) and running mvn archetype:generate from the command line. If you're doing a web application (which you may not be based on the question text) selecting "maven-archetype-j2ee-simple" or "maven-archetype-webapp" would be a pretty good kickstart. Doing so will set up a project for you that can then be used in eclipse (you could even use m2eclipse plugin to do dependency management from within eclipse).
It will turn out that Maven has a learning curve of its own, but my opinion is that the benefits outweigh the costs.
Good luck!
Download dom4j and put it on your classpath (in the referenced libraries tab)
From the stack trace, it looks like you're missing dom4j.jar. Hibernate (for Java) has a ton of dependencies. Make sure that you have all of Hibernates required dependencies added to your Eclipse project.
You need to put the dom4j jar on your classpath. You should be able to get it here:
http://www.dom4j.org/download.html
I think that hibernate uses version 1.6.1
To make all this easier, I would quickly learn Maven and then use the m2eclipse plugin.
I know it's a learning curve, but it will make everything massively easier at deploy time.

Categories

Resources