I am trying to run CnnSentenceClassification from deeplearning4j example. I moved this file to my Gradle project. When I run the class from the eclipse it works fine. However when I run it from ./gradlew run I get following error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at
main.CnnSentenceClassification.main(CnnSentenceClassification.java:75)
Caused by: java.lang.RuntimeException:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException:
Please ensure that you have an nd4j backend on your classpath. Please
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6089)
at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:201)
... 1 more
Caused by:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException:
Please ensure that you have an nd4j backend on your classpath. Please
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:258)
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6086)
... 2 more
I checked and nd4j-api-0.9.1.jar is in my classpath. This is my build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
repositories {
jcenter()
}
mainClassName="main.CnnSentenceClassification"
dependencies {
compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '0.9.1'
compile group: 'org.deeplearning4j', name: 'deeplearning4j-nlp', version: '0.9.1'
testCompile group: 'org.nd4j', name: 'nd4j-native-platform', version: '0.9.1'
compile group: 'org.nd4j', name: 'nd4j-api', version: '0.9.1'
compile "org.slf4j:slf4j-simple:1.7.25"
compile "org.slf4j:slf4j-api:1.7.25"
}
I was having the same problem. You need an ND4J backend, which means updating your dependency tree.
For Maven builds, add the following dependency to your project's pom:
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
For Gradle builds, just add the following line in your dependencies:
compile "org.nd4j:nd4j-native:0.9.1"
This native backend uses the CPU for computations.
There is another dependency for a CUDA-enabled graphics card.
I found this link helpful:
DL4J Performance Debugging
Edit: new link is here. https://deeplearning4j.konduit.ai/config/backends
Old content below:
You have test scope on the nd4j backend. An nd4j backend is NEVER optional.
https://nd4j.org/backend.html
The error is right in the message. We even give you a link with an explanation right in the stack trace.
Related
I am currently developing a webservice in java using the framework Dropwizard.
For the Rest API interface I was using JAX-RS. Since I needed to upload files with a POST-Request I added jersey-media-multipart to my Gradle dependencies. However suddenly intellij could not resolve the javax.ws.rs.* import statements but the newer jakarta.ws.rs and thus I changed the interface to jakarta. The problem now is that Dropwizard apparently still needs JAX-RS and so I get the following error with stacktrace:
java.lang.NoClassDefFoundError: javax/ws/rs/QueryParam
at io.dropwizard.jersey.validation.JerseyParameterNameProvider.getParameterNameFromAnnotations(JerseyParameterNameProvider.java:46)
at io.dropwizard.jersey.validation.JerseyParameterNameProvider.getParameterNames(JerseyParameterNameProvider.java:35)
at org.hibernate.validator.internal.util.ExecutableParameterNameProvider.getParameterNames(ExecutableParameterNameProvider.java:37)
at org.hibernate.validator.internal.properties.javabean.JavaBeanExecutable.getParameterName(JavaBeanExecutable.java:86)
at org.hibernate.validator.internal.metadata.aggregated.ParameterMetaData$Builder.build(ParameterMetaData.java:165)
at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.findParameterMetaData(ExecutableMetaData.java:436)
at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:391)
at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataBuilder$BuilderDelegate.build(BeanMetaDataBuilder.java:260)
at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataBuilder.build(BeanMetaDataBuilder.java:133)
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.createBeanMetaData(BeanMetaDataManagerImpl.java:206)
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanMetaData(BeanMetaDataManagerImpl.java:165)
at org.hibernate.validator.internal.engine.ValidatorImpl.buildNewLocalExecutionContext(ValidatorImpl.java:772)
at org.hibernate.validator.internal.engine.ValidatorImpl.access$200(ValidatorImpl.java:84)
at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.doValidate(ValidatorImpl.java:707)
at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.indexedValue(ValidatorImpl.java:681)
at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:26)
at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:16)
at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues(ValueExtractorHelper.java:42)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedContainerElementsForCurrentGroup(ValidatorImpl.java:651)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:598)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:629)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:590)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:172)
at io.dropwizard.configuration.BaseConfigurationFactory.validate(BaseConfigurationFactory.java:238)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:127)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:108)
at io.dropwizard.cli.ConfiguredCommand.parseConfiguration(ConfiguredCommand.java:128)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:74)
at io.dropwizard.cli.Cli.run(Cli.java:78)
at io.dropwizard.Application.run(Application.java:94)
at Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.QueryParam
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.QueryParam
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 33 more
Execution failed for task ':Application.main()'.
> Process 'command '/usr/lib/jvm/java-13-openjdk/bin/java'' finished with non-zero exit value 1
I dont know if my build.gradle helps resolving my problem but here is it with my dependencies:
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'application'
dependencies {
compile 'io.dropwizard:dropwizard-core:2.0.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '3.0.0-M1'
}
mainClassName = 'Application'
run {
args = ['server']
}
I am pretty helpless and googled a lot about dropwizard and found out that they apparently should support jakarta since version 2.0.0. I am currently using version 2.0.8 but still getting this internal bug.
I fixed it using the own dropwizard library dropwizard-forms and not the jersey-media-multipart.
My new gradle dependencies now look like this:
dependencies {
compile group: 'io.dropwizard', name: 'dropwizard-core', version: '2.0.8'
compile 'io.dropwizard:dropwizard-forms:2.0.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Now I can also use javax again and do not need to switch to jakarta.
We have a project that make use of 'jrs-rest-java-client', version: '6.3.1'
The site we used to get the jar from has a certificate issue since September. https://jaspersoft.artifactoryonline.com
We then had to get the jar from a different site.
https://jaspersoft.jfrog.io/
The problem is that a dependency require is missing, but if we use the jar that has "-jar-with-dependencies" it is working. I tried by downloading that jar locally and changing the .gradle to use the local version.
What I would prefer is to have the build to fetch that version directly without having to download first.
How do we specify what jar to use?
dependencies {
compile fileTree(dir: 'lib',
includes: [
'ojdbc8.jar',
])
//compile group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1'
compile group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1', USETHISONE: 'jar-with-dependencies'
//compile files("${buildDir}/jrs-rest-java-client-6.3.1-jar-with-dependencies.jar")
}
I have now tried as suggested;
repositories {
mavenCentral()
// to handle broked jasper reports dependencies
maven {
url 'http://jasperreports.sourceforge.net/maven2'
url 'https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/'
url "https://jaspersoft.jfrog.io/jaspersoft/jaspersoft-clients-releases"
}
}
dependencies {
implementation project(':common:project-common-properties')
implementation project(':common:project-common-mail')
implementation fileTree(dir: 'lib', includes: [
'ojdbc8.jar'
])
implementation group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1', classifier: 'jar-with-dependencies'
}
I'm still getting errors at build time...
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':services:notificationService:compileClasspath'.
> Could not find com.jaspersoft.jasperserver:jasperserver-dto:6.3.0.
Required by:
project :services:notificationService > com.jaspersoft:jrs-rest-java-client:6.3.1
That library is not required if the jrs-rest-java-client-6.3.1-jar-with-dependencies.jar is used.
Thanks all,
The solution was, as seen if the video (Thanks!)
adding a new url:
url "https://jaspersoft.jfrog.io/jaspersoft/jrs-ce-releases"
From the jfrog repo, it shows you how to do this:
compile(group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1', classifier: 'jar-with-dependencies')
Add the repo for gradle:
repositories {
jcenter {
name "jaspersoft-releases"
url "https://jaspersoft.jfrog.io/jaspersoft/jaspersoft-clients-releases"
}
}
I'd recommend switching from compile to implementation and using a shorthand to declare the dependency:
implementation "com.jaspersoft:jrs-rest-java-client:6.3.1:jar-with-dependencies"
Give a man a fish and you feed him for a day. Teach him how to fish and you feed him for his life time.
I decided to record a short clip of how I found the appropriate repositories for the artifacts you needed, on jfrog:
I start with software testing - using Cucumber, Java, gradle.
I try to learn this with the book "The Cucumber for Java Book"
But I try to do I with gradle instead of maven... But now I have some problems...
I stick on page 149. I have to give so dependecies:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
I try to "translate" this to gradle
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'io.cucumber:cucumber-java:2.4.0'
testCompile 'io.cucumber:cucumber-junit:2.4.0'
testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
}
Is this right?
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
After that I have to run:
mvn exec:java -Dexec.mainClass="nicebank.AtmServer"
But how can I do this with gradle?
I hope someone can help me :)
Your dependency looks good. Just one note: consider using implementation over compile as it improves the performance. Read about compile deprecation here.
You can also put your properties in gradle.properties file and reference them in the build script:
gradle.properties:
jettyVersion=9.4.12.v20180830
build.gradle:
implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: jettyVersion
Jetty team also published BOMs: — org.eclipse.jetty:jetty-bom:9.4.12.v20180830 in your case. If you use multiple projects of the same version you can import the BOM and skip the version completely:
dependencies {
implementation 'org.eclipse.jetty:jetty-bom:9.4.12.v20180830'
implementation 'org.eclipse.jetty:jetty-webapp'
implementation 'org.eclipse.jetty:jetty-runner'
}
As for the "exec" task: if you have only one main class in your project, like nicebank.AtmServer, consider using Gradle's Application Plugin:
plugins {
id 'application'
}
mainClassName = 'nicebank.AtmServer'
This way you don't need to create "exec" task manually, you'll get one (run) from the plugin. As a bonus you'll get two "distribution" tasks that will create a ready-for-distribution archive with your app: distZip and distTar.
As I said in my comment, the dependency for jetty-webapp seems OK but you should use implementation instead of compile ( compile has been deprecated, see Java dependency configurations):
implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
or
implementation "org.eclipse.jetty:jetty-webapp:9.4.12.v20180830"
For the equivalent of "maven exec:java" in Gradle , you could use the Gradle JavaExec task type: try to define a task in your build as follows:
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'nicebank.AtmServer'
}
(not tested, you migth have to adapt it) , and run it with
gradle runApp
You could alternatively use Gretty plugin to run your webapp (no need to define your own JavaExec task in this case), as documented here and here:
plugins{
// your existing plugins
id "org.gretty" version "2.2.0"
}
You can then run the application with:
gradle appRun
I'm building a SpringBoot-based project that will include Apache MetaModel. SpringBoot is version 1.5.8.
Starting up a SpringBoot app works fine, and I can get to published pages. At the moment, the project is pretty much a skeleton app with only very basic features.
However, as soon as I add:
compile 'org.apache.metamodel:MetaModel-full:5.0.0'
to my Gradle dependencies, startup fails with the notorious NoClassDefFound exception for FutureFallback. No other code added, and no configuration added or modified: reproducing the problem simply requires including the compile declaration to cause the startup failure.
I've tried including various versions of Guava and of MetaModel itself, as recommended by other answers, but none of them change the startup failure.
My gradle.build is currently thus:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1'
}
}
apply plugin: 'java'
apply plugin: 'org.junit.platform.gradle.plugin'
repositories {
mavenCentral()
}
dependencies {
compile project(':commons')
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
compile 'org.apache.metamodel:MetaModel-full:5.0.0'
compile 'mysql:mysql-connector-java:8.0.8-dmr'
compile 'com.microsoft.sqlserver:mssql-jdbc:6.3.4.jre8-preview'
compile 'org.reflections:reflections:0.9.11'
compile 'com.datastax.cassandra:cassandra-driver-core:3.3.1'
// compile 'com.google.guava:guava:23.4-jre'
compile 'com.google.guava:guava:20.0'
testCompile (
'org.junit.jupiter:junit-jupiter-api:5.0.1',
'org.mockito:mockito-core:2.10.0'
)
testRuntime(
'org.junit.jupiter:junit-jupiter-engine:5.0.1',
'org.mockito:mockito-core:2.10.0'
)
}
Evidence of tinkering with Guava versions is evident. Versions 16, 19, 20 and 23.4-jre have been tried.
Ideas for other avenues of repair greatly appreciated.
I am having issues with app crashing and giving this stack trace
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/codec/digest/DigestUtils;
at com.ryko.fstwo.wrapper.DigestUtilsWrapper.sha1(DigestUtilsWrapper.java:7)
...
Didn't find class "org.apache.commons.codec.digest.DigestUtils" on path: <really long path name>
I have gone through all the threads on here I can find about this problem, but cant find a resolution. In my libs folder I have commons-collections-3.2.1.jar, In my dependencies section on build.gradle I have
compile 'org.apache.commons:commons-collections4:4.1' and
compile files('libs/commons-collections-3.2.1.jar').
I have read through these but can't find a working solution
1, 2, 3 and many others
I guess that you need a dependency to commons-codec. It is available in maven central repo.
For example, add this to the dependencies section of your build.gradle:
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
Or you you prefer the shorter option:
compile group: 'commons-codec:commons-codec:1.10'
you need have changes,such as
dependencies {
implementation 'commons-codec:commons-codec:1.10'
}