I am very new to using cucumber (started today).
It seems simple enough but I am having issues running a basic feature.
Feature: Proof of concept that my framework works
Scenario: My first test
Given this is my first step
When this is my second step
Then this is my final step
I know there is no code for it to test, but I wanted it to return the fact that the scenarios are undefined.
I did some research and realised I had a .jar file which was unnecessary, I have since removed that.
I still have the following issue:
Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/lexer/Encoding
Caused by: java.lang.ClassNotFoundException: gherkin.lexer.Encoding
There some more info from the exception.
Is there any other info I should provide?
Any help would be appreciated
I had this same problem when running through the First Steps chapter in The Cucumber for Java book.
It says to download the latest version of the Gherkin jar (among others) from
http://repo1.maven.org/maven2/info/cukes/gherkin/
Below is the listing, where, on the webpage, each one is a directory-link containing the jar. My mistake was thinking that the bottom-most version is the most recent version. It's not. For all of the other jars, the bottom-most is indeed the most recent version.
When using the bottom-most Gherkin jar, I get the CNFX exactly as you describe:
Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/lexer/Encoding
Caused by: java.lang.ClassNotFoundException: gherkin.lexer.Encoding
The version-number listing, as on the above webpage:
2.10.0/
2.11.0/
2.11.1/
2.11.2/
2.11.4/
2.11.5/
2.11.6/
2.11.7/
2.11.8/
2.12.0/
2.12.1/
2.12.2/
2.4.16/
2.4.17/
2.4.18/
2.4.19/
2.4.20/
2.4.21/
2.5.0/
2.5.1/
2.5.2/
2.5.3/
2.5.4/
2.6.0/
2.6.1/
2.6.2/
2.6.3/
2.6.4/
2.6.5/
2.6.6/
2.6.7/
2.6.8/
2.6.9/
2.7.0/
2.7.1/
2.7.2/
2.7.3/
2.7.4/
2.7.5/
2.7.6/
2.7.7/
2.8.0/
2.9.0/
2.9.1/
2.9.2/
2.9.3/
Make sure you have the cucumber java libraries in your CLASSPATH.
Its an setup issue as it is not finding the required cucumber classes to interpret gherkin statements.
Provide more info on the files you included in the setup.
Rather than downloading individual jars, use a package manager to download the dependencies.
Using Maven, add the following dependencies to the pom.xml:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
NB. This is currently the latest version.
Make sure to use the same version for all Cucumber dependencies.
Related
I receive
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.valueextraction.ValueExtractorManager
when using JDK version 1.8.0_265 and having one or more DL4J dependencies (version 1.0.0-beta7) in my Maven dependencies in Spring Boot application. This error doesn't occur on JDK v1.8.0_272.
My application runs on Spring Boot 2.3.7.RELEASE. I checked DL4J dependencies and listed the ones that cause this exception below:
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>1.0.0-beta7</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>arbiter-deeplearning4j</artifactId>
<version>1.0.0-beta7</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-ui-model</artifactId>
<version>1.0.0-beta7</version>
</dependency>
This happens on both Linux and Windows with JDK (AdoptOpenJDK) v.1.8.265 but it works fine with JDK v1.8.272.
It's a bit critical for us to stick to 265 version and it's impossible to stop using Hibernate in the application.
Can't share full stacktrace as it's related to the project code but one of the places where this exception is throw is while instantiating javax.validation.Validation:
Validation.buildDefaultValidatorFactory().getValidator(); // this line causes NoClassDefFoundError
I ran mvn dependencies:tree and there's no Hibernate dependencies shown for the whole project so I assume the the dependencies above use old version of Hibernate that causes error because it conflicts with Hibernate from Spring but that's just an assumption because it definitely has something to do with JDK.
Is there a way to identify what exactly causes a problem and fix it without moving to new JDK?
I'm about to finish my master thesis. The program, i developed, is a maven project with javaFx declared as dependencies
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>16-ea+4</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>8.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>16-ea+4</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>16-ea+4</version>
</dependency>
When I'm creating the jar using Maven-install the program runs on Oracle-JDK. But on openJDK it throws a java.lang.ClassNotFoundException.
My understanding is, that javaFX is not included in both JDKs anymore. Thats why I'm unsing maven and build the jar with all dependencies. That way it should find javaFx and start the program regardless the used JDK.
Assuming my assumption is correct that the error has something to do with javaFX.
To compile the Program I'm using JavaSE 13. It runs perfectly using Oracle JDK 15. But it throws a java.lang.ClassNotFoundException using openJDK 14 or 15.
---EDIT---
I'm not totaly sure if this error is regarded to JavaFX.
I'm starting the jar on the console with
java -jar "C:...\test.jar"
This works on the OracleJDK but not on the openJDK. Then the Console prinst:
Error: Could not find or load main class C:\...\test
Caused by: java.lang.ClassNotFoundException: C:\...\test
I know how to print the stacktrace, using the IDE. But is it possible to print the stacktrace using the console in this case?
If so I will do it an edit this question to provide more info.
I would be so grateful for your help. I panic ^^
You are only providing us with some fragments of your setup. So it is difficult to give any specific advice. From what I see I'd say that your program cannot work on any Java which does not contain JavaFX because you do not provide the required arguments in your launch command. Have a look here for proven ways to launch JavaFX correctly: https://openjfx.io/openjfx-docs/
Do you have a MANIFEST.MF file? IT should point towards the class that has your public static void main(String[] args) method <-- Your main method.
Example:
MANIFEST.MF
Manifest-Version: 1.0
Main-Class: classes.TestClass
Helpful stackoverflow: Could not find or load main class with a Jar File
https://taylorial.com/cs1021/Jar.htm#jarwithjavafxpackagesincluded
my Prof just responded and says that it was just a typo in his commandline.
It works perfectly fine.
I will delete this question in view hours, cause it is not really a problem.
Thank you very much.
After using Eclipse EE and Eclipse Axis2 Code Generator plugin, I got a two
operation generated java files with the same error:
Cannot instantiate the type ADBDataSource ConcatRequest.java
Cannot instantiate the type ADBDataSource ConcatResponse.java
Here is the problem:
org.apache.axiom.om.OMDataSource dataSource = new
org.apache.axis2.databinding.ADBDataSource(this,MY_QNAME);
This code appears in both ConcatRequest.java and ConcatResponse.java and
causes the error. I see that ADBDataSource is abstract and cannot be instantiated.
I'm totally new to Axis and I don't know how to solve this problem. Please help.
I had this problem due to a version mismatch of axis2-adb. Safest way to deal with this problem is to have a look at the lib folder of the eclipse plugin (eclipse/(dropins|plugins)/ ... .jar). Then look for the versions of the dependecies and include them (the ones you actually need) in your build path.
i faced the same issue while generating JAVA Stubs from WSDL. Following are the steps I used to solve the issues :
Follow the below link to generate Stubs : https://support.pcmiler.com/en/support/solutions/articles/19000053078-java-client-axis2-code-generator-for-eclipse.
Now there is a small tweak to this link. After doing point no 10 & 11 as mentioned in the above link , only use axis2-1.7.9 to generate your stubs and when they are generated used the jars mentioned in the \axis2-1.7.9\lib in your build path.
Hope this solves your issue.
Old topic, but I was working on a legacy project with several subprojects.
In one of those subprojects, I came across this same message.
It also was a version problem (Maven dependencies...).
Ctrl-Click (in Eclipse/IntelliJ) on "ADBDataSource". Which version is it? For me it was 1.5.6, but in my pom.xml there was only
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.7.4</version>
</dependency>
However, this subproject had a dependency on another subproject which WAS using 1.5.6 (I found it by searching in the whole project for "1.5.6" using the Notepad++ "Search / Find in Files" menu option).
Then in the dependency to that other project, I excluded 1.5.6 :
<dependency>
<groupId>com.group.id</groupId>
<artifactId>anotherproject</artifactId>
<version>version</version>
<exclusions>
<exclusion>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
</exclusion>
</exclusions>
</dependency>
After adding the exclusion, the project did use the 1.7.4 version.
I am trying to create a PDF/A document using itext and java with the following code:
PdfAWrite writer = PdfAWriter.getInstance(myDoc, myStream, PdfAConformanceLevel.PDF_A_1A);
but I keep getting this exception:
java.lang.NoClassDefFoundError: com/itextpdf/text/log/CounterFactory
at com.itextpdf.text.pdf.PdfAWriter.<init>(PdfAWriter.java:210)
at com.itextpdf.text.pdf.PdfAWriter.getInstance(PdfAWriter.java:86)
this is my pom.xml
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.3</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-pdfa</artifactId>
<version>5.5.3</version>
</dependency>
can anyone tell what should I do to fix this problem?
Thanks
I get similiar exceptions when I have the said class in more than one jar. Maybe you should check your classpath for duplicates. Maybe different versions of the same library coexist. If you're using Eclipse, have a look at the 'Dependency hierarchy' view of the pom and try to locate a duplicate.
Looks like you miss the itextpdf.jar in your classpath. Download the jar and add it to your classpath
The current release of Primefaces libraries refers to an older release of iText. If you try to install the latest iText distribution you will end up to the following error:
java.lang.NoClassDefFoundError: com/lowagie/text/
This is due to the fact that in the recent iText release the package com/lowagie/text has been renamed as com/itextpdf/text. So until this is fixed use the suggested iText release (2.1.7) or at least verify the package structure.
This might be useful:
http://www.mastertheboss.com/jboss-web/primefaces/export-your-datatable-to-excel-and-pdf-using-primefaces?showall=&start=1
I have a Maven Java project that uses Mashape Unirest for sending HTTP requests to other URLs. I am currently writing an integration test (using TestNG) that sends a normal HTTP request using Unirest. When I run the integration test through Maven (via the Failsafe plugin), the request is sent out successfully. However, when I try to run the integration test via Eclipse, I keep on getting the following error:
FAILED: getCurrentTimeTest
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.mashape.unirest.http.options.Options.refresh(Options.java:41)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:27)
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:141)
at com.mashape.unirest.http.HttpClientHelper.requestAsync(HttpClientHelper.java:80)
at com.mashape.unirest.request.BaseRequest.asStringAsync(BaseRequest.java:56)
at ...
I am also able to reproduce this error using a basic Java application script.
I have made sure that the dependencies I am using in my pom.xml file are the latest and greatest, as seen below:
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
I have also checked out the source code of BasicLineFormatter.java, both from the source file downloaded to Eclipse and from Apache's Httpcore Github repo. In the Github repo, notice how the INSTANCE field is defined for the 4.3.x branch and the trunk branch, but not in older branches like 4.2.x. However, I am indeed using version 4.3.2 in my project, so I should be using a JAR file for Httpcore that has the latest version of BasicLineFormatter. I know that, based on the Maven Dependencies JAR files that are in my project, that I am indeed using the latest versions of these Apache dependencies, not the older versions specified as downstream dependencies of my project.
I have checked other various SOF and blog posts about this issue, such as Mashape Unirest Java : java.lang.NoClassDefFoundError and this blog post too, but they all seem to be talking about solving the NoSuchFieldError problem for Android. However, I'm dealing with a standalone Java application, not an Android application.
I am at a loss in determining how to troubleshoot this issue. Anyone have any idea what I need to do?
UPDATE
Instead of showing my test case, I will reduce the illustration of a reproduction of this problem to just a simple one-liner Java application, because the problem exists with any Java application or test case run through Eclipse, not just one particular test:
System.out.println(Unirest.get("http://www.google.com").asStringAsync().get().getBody());
Normally, this should print the HTML of the Google home page, but I instead get the NoSuchFieldError stack trace.
FIXED!
The problem was that the AWS SDK (it's on my classpath because I'm developing for Elastic Beanstalk) had a conflicting JAR file. Using Oleg's solution (thanks BTW), I printed the following output in a unit test:
jar:file:/some/path/aws-java-sdk/1.7.1/third-party/httpcomponents-client-4.2.3/httpcore-4.2.jar!/org/apache/http/message/BasicLineFormatter.class
I'll have to rearrange my classpath so that AWS SDK is no longer conflicting.
The only plausible explanation to this problem is there is an older version of HttpCore on the classpath (unless you also want to consider a possibility of green men from Mars messing with your computer remotely from a flying saucer).
You can add this snippet to your code to find out what jar the class gets picked up from. This might help find out why that jar is on your classpath in the first place.
ClassLoader classLoader = MyClass.class.getClassLoader();
URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
System.out.println(resource);
This basically tells me that in my case the jar resides in the local maven repository and likely to have been added to the classpath by Maven
jar:file:/home/oleg/.m2/repository/org/apache/httpcomponents/httpcore/4.3.1/httpcore-4.3.1.jar!/org/apache/http/message/BasicLineFormatter.class
As already mentioned by previous comments, It's mainly because of the conflicting versions of httpcore jar, the static field INSTANCE is been added to BasicLineFormatter class in versions > 4.3.1, Though you might have added the latest version of the httpcore jar in your dependencies, but its highly possible that other (lower) version of jar is getting picked up.
So, first to confirm that, wrong jar is getting picked up, Use the following line of code -
ClassLoader classLoader = <Your Class>.class.getClassLoader();
URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
System.out.println(resource);
If this prints, the lower version of the jar, then it's confirmed that it's picking the lower version of the httpcore jar (May be from other dependencies of your project),
Solution -
Add following maven/gradle dependencies at the top of dependency list (Or above the other project dependency which caused the conflict) -
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>
I faced the same exception using unirest:
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at com.mashape.unirest.http.options.Options.refresh(Options.java:55)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:36)
And found it was due to DefaultConnectionKeepAliveStrategy.INSTANCE; and the conflicting jar was apache-httpcomponents-httpclient.jar in my classpath. Adding this post to help anyone who faces similar exception
I got this Exception: Caused by: java.lang.NoSuchFieldError: INSTANCE
Solution:
This happens if you have two different version classes in your classpath…. […], So I first find that class (one version of class), click that class, select build path, then I click remove from build path.
if you are using aws sdk this error occurs because of dependency mismatch.
To avoid this error do the following:
1.Put the dependecies in the required order aws sdk and the end preferably
2.Add shade plugin to the project
This solved my problem
you can refer to my answer in
HTTPClient Example - Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
my case is i have httpclient-4.4.1.jar, and httpcore-4.4.1.jar in my class path, but JVM loaded BasicLineFormatter from httpcore-4.0.jar