Unable to run cucumber features directly through intellij run configuration - java

I am getting this stack trace when running a very basic feature which just opens a browser, navigates to google.com and search some string.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/transaction/TransactionStatus
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86)
at cucumber.runtime.Runtime.<init>(Runtime.java:92)
at cucumber.runtime.Runtime.<init>(Runtime.java:70)
at cucumber.runtime.Runtime.<init>(Runtime.java:66)
at cucumber.api.cli.Main.run(Main.java:35)
at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException:
org.springframework.transaction.TransactionStatus
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more
Can someone tell me what is missing here?

For Intellij 2018.1 and i guess for early versions, the Run configuration by default gets the Glue 'cucumber.api.spring' , you should switch it for 'com.foreach.cuke'
Go to 'Edit Configurations' - 'Cucumber' - Glue: com.foreach.cuke ...

The below dependency is missing. Default glue cucumber.api.spring is not able to find class transaction so it throws an error. Add dependency to your pom.xml and it will solve your issue
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>

You should switch The Run configuration to 'com.foreach.cuke' instead of 'cucumber.api.spring'..
Go to 'Edit Configurations' - 'Cucumber' - Glue: com.foreach.cuke ...

As far as NoClassDefFoundError is concerned, it arises due to mismatch between the following components :
JDK version - Solution - Keep the JDK version updated to the recent releases.
JUnit version - Solution - Keep the JUnit version in sync with cucumber version.
Selenium version - Solution - Update the Selenium version to the recent release versions.
WebDriver Binary version - Solution - Update the WebDriver version to the recent release versions.
Web Browser Binary version - Solution - Update the Web Browser version to the recent release versions.

Related

java.lang.ClassNotFoundException while using docker-java

We are using this library to do 'docker pull' from docker hub and to check whether an image with a given name already exists. We need this to work in Linux, Mac and Windows having the latest version of docker installed. But in several cases, we have hit the error mentioned in the title and that error is coming from jersey-client that is internally used by this library.
We have tested using docker-java 3.1.5 and the latest 3.2.5 and on docker 19.03.5 and also the latest docker. The latest docker version varies on different platforms as mentioned below:
Linux (19.03.12)
Mac (19.03.8)
Windows (19.03.8)
Attached result of our tests
I am sharing a code snippet of what we are trying:
DockerClient dockerClient;
dockerClient = DockerClientBuilder.getInstance().build();
String imageName = "SOME_IMAGE_NAME";
List images = dockerClient.listImagesCmd().withImageNameFilter(imageName).exec();
if(!images.isEmpty()){
dockerClient.removeImageCmd(images.get(0).getId());
}
dockerClient.pullImageCmd(imageName).exec(new PullImageResultCallback()).awaitCompletion(DOCKER_PULL_WAIT_TIME, TimeUnit.SECONDS);
We are using Java 8.
If anyone has faced this kind of an issue before and solved it, can you please suggest how we should approach this problem?
Sharing the stacktrace:
java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
2020-07-13 22:14:59,255 ERROR [docker-java-stream--1445483847] ResultCallbackTemplate - Error during callback
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122) ~[jsr311-api-1.1.1.jar:?]
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91) ~[jsr311-api-1.1.1.jar:?]
at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69) ~[jsr311-api-1.1.1.jar:2.1.6]
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:80) ~[jsr311-api-1.1.1.jar:2.1.6]
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:99) ~[jsr311-api-1.1.1.jar:2.1.6]
at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:48) ~[jersey-client-2.30.1.jar:?]
at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:274) ~[jersey-client-2.30.1.jar:?]
at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:56) ~[jersey-client-2.30.1.jar:?]
at com.github.dockerjava.jaxrs.JerseyDockerHttpClient.execute(JerseyDockerHttpClient.java:291) ~[docker-java-transport-jersey-3.2.5.jar:?]
at com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:228) ~[docker-java-core-3.2.5.jar:?]
at com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269) ~[docker-java-core-3.2.5.jar:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_252]
Caused by: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358) ~[catalina.jar:8.5.57]
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180) ~[catalina.jar:8.5.57]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_252]
at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_252]
at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:62) ~[jsr311-api-1.1.1.jar:?]
at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:155) ~[jsr311-api-1.1.1.jar:?]
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:105) ~[jsr311-api-1.1.1.jar:?]
... 11 more
The default transport that is used by docker-java library is jersey-client which has issues on non-Unix platforms. For that I had to explicitly use a different transport. I used Apache httpclient 5 which is anyway planned to be made default in the future releases of docker-java.
A list of transports for docker-java can be found at https://github.com/docker-java/docker-java/blob/master/docs/transports.md .

java.lang.NoClassDefFoundError: oracle/dms/console/DMSConsole

My OS = CentOS-7
Oracle 18.4 XE
Java 8 JDK + Tomcat 8
I facing the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/dms/console/DMSConsole
at oracle.jdbc.driver.DMSFactory.<clinit>(DMSFactory.java:46)
at oracle.jdbc.driver.PhysicalConnection.createDMSSensors(PhysicalConnection.java:1713)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:849)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:443)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:712)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Test.main(Test.java:9)
Caused by: java.lang.ClassNotFoundException: oracle.dms.console.DMSConsole
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 9 more
I searched a lot but was unable to find any forum where I can see aforementioned error related to oracle 18.4.0.
I searched my whole server even unzipped all ojdbc*.jar but not found DMSConsole anywhere
I removed all previous jdbc jar drivers and downloaded latest ojdbc8-full.tar.gz driver form this LINK but nothing fixed the problem
Best Regards
What are you trying to do? If you are planning to use dms jar then you should use
ojdbc8dms.jar. Check out the question "What are the different JAR files on the 19.3 JDBC driver download page for?" in JDBC FAQ
You can get these jars from maven. Check out the blog for details. You can also download these from ojdbc8-debug.tar.gz from OTN. Make sure to have dms.jar in the classpath.
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8dms</artifactId>
<version>19.6.0.0</version>
This can be solved by adding a correct dms.jar but when not detailled log is needed the following jars are the minimum to include
ojdbc8.jar
orai18n.jar

wildfly swarm deployment crash with java 9

Packaging a hello world application generated by the wildfly swarm generator and built with Java9 crashes when deploying the application.
It seems that the reason is the swarm/undertow dependency to the org.ow2.asm:asm-all:5.0.4 which is not Java9 ready.
Is there a known workaround, or a known date when swarm will be ready for Java9?
The stacktrace is:
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.isJAXRS(JAXRSArchiveImpl.java:117)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.isJAXRS(JAXRSArchiveImpl.java:96)
at org.wildfly.swarm.jaxrs.JAXRSArchive.isJAXRS(JAXRSArchive.java:55)
at org.wildfly.swarm.jaxrs.internal.DefaultJAXRSWarDeploymentFactory.create(DefaultJAXRSWarDeploymentFactory.java:46)
at org.wildfly.swarm.jaxrs.internal.DefaultJAXRSWarDeploymentFactory$Proxy$_$$_WeldClientProxy.create(Unknown Source)
org.wildfly.swarm.container.runtime.deployments.DefaultDeploymentCreator.createDefaultDeployment(DefaultDeploymentCreator.java:69)
The class files in JDK 9 are v53.0 so you need ASM 6. ASM has always thrown IAE when encountering class files that are newer that it supports.
The IllegalArgumentException can be possibly caused by different class version when scanning the bytecode which in your case which is done by org.ow2.asm:asm-all:5.0.4.
We faced similar issue faced in jetty.project#1758 which I'd to try and solve by building the jetty.project by myself but to eventually realize that org.ow2.asm would chain me back still.
The latest available version of asm on maven is :
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<version>6.0_BETA</version>
</dependency>
In case of jetty (and probably swarm as well) they were not able to integrate this as 6.0_BETA is not a valid OSGI version number:
Caused by: java.lang.IllegalArgumentException: invalid range
"[6.0_BETA,6.0_BETA]": invalid version "6.0_BETA": non-numeric
"0_BETA"
Related to the above a read to how jetty tried solving it.
There is already a tracker to the ow2.asm invalid version bug which you can follow.

Apache Flink WordCount Example - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/common/functions/FlatMapFunction

I followed this guide, but I get an Exception if I run WordCount from my IDE
/usr/lib/jvm/java-8-oracle/bin/java -Didea.launcher.port=7536 -Didea.launcher.bin.path=/home/marc/Programs/idea-IC-162.2032.8/bin -Dfile.encoding=UTF-8 -classpath "/usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/home/marc/apache flink/flink.gelly/target/classes:/home/marc/Programs/idea-IC-162.2032.8/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain haw.bachelor.flink.gelly.WordCount
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/common/functions/FlatMapFunction
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.common.functions.FlatMapFunction
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
my environment:
Ubuntu 14.04 LTS
Oracle Java 8
Maven 3.0.5
intellij community edition
here is what i changed setting and the error was gone
In Intellij IDEA (2020.3), the UI is a little different.
Steps:
Activate Run-Configuration dropdown
click Edit Configurations...
click Modify Options
select include dependencies with "Provided" scope
Click "done"
Flink sources should now be included, which should resolve the error encountered - it did for me!
If you run it in your IDE, you must select "mainRunner" instead of "root" from the "Run Configurations" menu. It makes the classpath load the classes that are "provided" in the project.
I solved this issue by deactivating 'build-jar' profile in Maven in the IDE. It seems that turning that off will enable run-time classes to be available.

Unable to run a storm-starter topology from the Storm tutorial

When following the guide in the storm-starter repo, I'm unable to actually run any topology- like the ExclamationTopology.
mvn clean install -DskipTests=true ran successfully, executed from the top level Storm repo, as did mvn package at the storm-examples level.
When I try to run storm jar target/storm-starter-2.0.0-SNAPSHOT.jar org.apache.storm.starter.ExclamationTopology, I get the error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/storm/topology/IRichSpout
I'm running OS X, Java version:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Maven version 3.3.9.
Does anyone have any ideas on why I'm getting this error and what I should change in my setup?
Full error output:
Running:
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -client -Ddaemon.name= -Dstorm.options= -Dstorm.home=/Users/zachary/apache-storm-0.10.0 -Dstorm.log.dir=/Users/zachary/apache-storm-0.10.0/logs -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /Users/zachary/apache-storm-0.10.0/lib/asm-4.0.jar:/Users/zachary/apache-storm-0.10.0/lib/clojure-1.6.0.jar:/Users/zachary/apache-storm-0.10.0/lib/disruptor-2.10.4.jar:/Users/zachary/apache-storm-0.10.0/lib/hadoop-auth-2.4.0.jar:/Users/zachary/apache-storm-0.10.0/lib/kryo-2.21.jar:/Users/zachary/apache-storm-0.10.0/lib/log4j-api-2.1.jar:/Users/zachary/apache-storm-0.10.0/lib/log4j-core-2.1.jar:/Users/zachary/apache-storm-0.10.0/lib/log4j-over-slf4j-1.6.6.jar:/Users/zachary/apache-storm-0.10.0/lib/log4j-slf4j-impl-2.1.jar:/Users/zachary/apache-storm-0.10.0/lib/minlog-1.2.jar:/Users/zachary/apache-storm-0.10.0/lib/reflectasm-1.07-shaded.jar:/Users/zachary/apache-storm-0.10.0/lib/servlet-api-2.5.jar:/Users/zachary/apache-storm-0.10.0/lib/slf4j-api-1.7.7.jar:/Users/zachary/apache-storm-0.10.0/lib/storm-core-0.10.0.jar:target/storm-starter-2.0.0-SNAPSHOT.jar:/Users/zachary/apache-storm-0.10.0/conf:/Users/zachary/apache-storm-0.10.0/bin -Dstorm.jar=target/storm-starter-2.0.0-SNAPSHOT.jar org.apache.storm.starter.ExclamationTopology
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/storm/topology/IRichSpout
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.storm.topology.IRichSpout
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Edit:
After following the suggestions in the answers below of removing the scope line from the pom.xml, this error was gone, but replaced by:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/Users/zachary/apache-storm-0.10.0/lib/storm-core-0.10.0.jar!/defaults.yaml, jar:file:/Users/zachary/storm/examples/storm-starter/target/storm-starter-2.0.0-SNAPSHOT.jar!/defaults.yaml]
Final Edit:
For any future googler, I ended up not getting the storm-starterexamples running via the commandline on a LocalCluster. I instead set up a new project with Maven, adding storm-core as a dependency, following [this] (https://github.com/mbonaci/mbo-storm/wiki/Storm-setup-in-Eclipse-with-Maven,-Git-and-GitHub) general guide. Then, in Eclipse, I was able to import the right packages from storm to do the examples, like ExclamationTopology. I rewrote that class using the same imports (changed to import backtype.storm.Config, etc). Then, running the file as is just works.
This quick Maven guide helps too.
To be little bit more precise with regard to Nick's answer.
In storm-starter/pom.xml the dependency storm-core is specified with scope "provided":
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>${project.version}</version>
<!--
Use "provided" scope to keep storm out of the jar-with-dependencies
For IntelliJ dev, intellij will load properly.
-->
<scope>${provided.scope}</scope>
</dependency>
If you run locally using LocalCluster you need to include storm-core as dependency with default scope "compile", ie, just remove the scope tag, and run mvn -DskipTests package in storm-starter again.
NoClassDefFoundError regarding Storm, usually refers to errors coming from the <scope> tag in your pom.xml.
If you are trying to run the project on a cluster of machines where you have installed Storm, the <scope> should be "provided" (<scope>provide</scope>), else if you are trying to execute the topology locally, the scope must be set to "compile".
Hope this helps.
the first time I tried to run storm-starter, I got blocked by the missing pom or some dependencies.
I read the document again. Then I found I should install the storm first from the root directory of project not the storm-starter directory.
scope provided should be fine.
IDE will try to find it from local repository
I too faced the same issue (Initially NoClassDefFoundError later multiple defaults.yaml)
For me following config change in intellij solved the problem.
Run ---> Edit configurations ---> Tick - Include dependencies with "provided" scope.
So basically when you are running in cluster mode, storm-core's scope should be "provided" in pom.xml. And above configuration will ensure that dependencies will be provided from cluster at run-time.

Categories

Resources