Gradle wrapper NoClassDefFoundError - gradle

When I run ./gradlew I get
Exception in thread "main" java.lang.NoClassDefFoundError:
org/gradle/wrapper/GradleWrapperMain Caused by:
java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
My project compiles using the Android Studio but stopped compiling from command line

Probably something went bad. The solution:
Install gradle: brew install gradle
Regenerate wrapper: gradle wrapper

See https://github.com/drone/drone/issues/256
My .gitignore had *.jar in it, so I wasn't getting all the jars I needed in my repository.

I had the same, or similar, problem when trying to build my app from command line, but with an exception thrown for 'java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context' which did not happen when building within Android Studio. I found out that AS brings along it's own JRE and I resolved the issue by setting 'JAVA_HOME' to the AS JRE path. In my case it turned into:
$ JAVA_HOME=/opt/android-studio/jre ./gradlew build
You can find this path under 'File' -> 'Project Structure' -> 'SDK Location', see screenshot.

I hit this issue when I have a directory with a ":" (no quotes, just a colon) in it.
This was on a linux machine.
Before:
"my:directory"
as in
/Users/me/projects/project1/my:directory/
then i renamed it to
/Users/me/projects/project1/my_directory/
and the error went away.

Related

Gradle build failing after update

Getting exception while gradle/gradlew build. Build without test cases is successful. This happening when I updated the gradle to 6.0.1
Works fine for gradle 5.6/6.2 version.
Could not write standard input to Gradle Test Executor 2.
java.io.IOException: The pipe is being closed
at java.base/java.io.FileOutputStream.writeBytes(Native Method)
at java.base/java.io.FileOutputStream.write(FileOutputStream.java:348)
at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
at org.gradle.process.internal.streams.ExecOutputHandleRunner.forwardContent(ExecOutputHandleRunner.java:68)
at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:53)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:835)
Error: Could not find or load main class worker.org.gradle.process.internal.worker.GradleWorkerMain
Caused by: java.lang.ClassNotFoundException: worker.org.gradle.process.internal.worker.GradleWorkerMain
FAILURE: Build failed with an exception.
I just had this happen, and found that stopping the gradle daemon resolved it for me:
gradle --stop
or
./gradlew --stop
depending on your setup (the daemon is relaunched when you attempt to build again).
I encountered this error and the one method I found was dump the whole $HOME/.gradle cache and then rebuild the project.
Starting/Stopping IntellijIDEA and/or rebuilding did not help.
You know you have jumped the complexity shark somewhere when running lowly test cases starts to fail for obscure reasons.
Granted, this happened after a machine crash. But still..
If its a windows system, then try deleting the .gradle folder from the user directory and try to build the gradle. This should solve the issue

Use Nd4j in an Intellij project

I'm trying to use Nd4j in a Kotlin project in Intellij IDEA. In Project Structure -> Libraries, I used the "From Maven" command to add the following libraries.
org.deeplearning4j:deeplearning4j-core:1.0.0-beta
org.nd4j:nd4j-native-platform:1.0.0-beta
org.datavec:datavec-api:1.0.0-beta
With those libraries I can compile my project, but when I run it fails with an exception.
Caused by: java.lang.RuntimeException: ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html
at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:51)
at org.nd4j.nativeblas.NativeOpsHolder.<clinit>(NativeOpsHolder.java:19)
... 10 more
Caused by: java.lang.UnsatisfiedLinkError: no jnind4jcpu in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
at org.bytedeco.javacpp.Loader.load(Loader.java:980)
at org.bytedeco.javacpp.Loader.load(Loader.java:879)
at org.nd4j.nativeblas.Nd4jCpu.<clinit>(Nd4jCpu.java:10)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:938)
at org.bytedeco.javacpp.Loader.load(Loader.java:879)
at org.nd4j.nativeblas.Nd4jCpu$NativeOps.<clinit>(Nd4jCpu.java:1310)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:29)
... 11 more
Caused by: java.lang.UnsatisfiedLinkError: no nd4jcpu in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
at org.bytedeco.javacpp.Loader.load(Loader.java:965)
... 21 more
Looking through the project folder I see that IDEA has downloaded lots of jar files for nd4j-native-platform, but there's no sign of any JNI libraries. What else do I have to do?
Intellij's "From Maven" feature doesn't support the classifiers that JavaCPP and ND4J (and other libraries that use native code) use. Maven will work great but if you really can't use it for some reason, you can manually add the nd4j-native-1.0.0-beta2-macosx-x86_64.jar file and openblas-0.3.0-1.4.2-macosx-x86_64.jar file. That should be enough to run simple things, but you'll have to manually do that for every other native dependency as you use more and more stuff (like OpenCV). That's why Maven is recommended.
If you include those 3 dependencies, there are zero reasons why it should fail unless you're on an unsupported OS for some reason.
We support everything from android to IBM power so that is unlikely though.
I'm also confused by what you mean about not seeing any JNI libraries. Those are all in the jar files. We use javacpp (which we also maintain) to manage those things.
You will find those libraries under ~/.javacpp/cache - you should not have any reason to touch those though.
Could you clarify what you are looking for there?
Beyond that, there is nothing else you have to do. I'm assuming something just didn't load correctly.
Our standalone pom works out of the box: https://github.com/deeplearning4j/dl4j-examples/blob/master/standalone-sample-project/pom.xml - maybe double check this, that or reload. I can only assume you created the project wrong somehow. File -> New Maven project should be all you need to do.

Stanford POStagger demo fails on Windows

I am trying to run the Stanford POSTagger (version 3.6) using the Windows cmd and I am having problems. I am following the instructions in the README with the corrections for Windows.
I have a directory (C:\Program Files\stanford-postagger-full-2015-12-09>)with the POSTagger files.
In the command prompt I am at this directory (..Stanford-postagger-full...).
1)The command: javac -cp stanford-postagger.jar TaggerDemo.java is executed correctly (no error message)
2)The command: java -cp ".;stanford-postagger.jar" TaggerDemo models\wsj-0-18-left3words.tagger sample-input.txt fails. I am getting the following error:
C:\Program Files\stanford-postagger-full-2015-12-09>java -cp
".;stanford-postagger.jar" TaggerDemo
models\wsj-0-18-left3words.tagger sample-input.txt
Exception in thread
"main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at edu.stanford.nlp.io.IOUtils.(IOUtils.java:42)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.(MaxentTagger.java:298)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.(MaxentTagger.java:263)
at TaggerDemo.main(TaggerDemo.java:20) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 5 more
Any suggestions about my error? Am I at the correct directory to run the commands?
I believe there is another .jar file that you need to add to the classpath. If you look at the error, you'll see that the class that isn't found is org/slf4j/LoggerFactory, which is in .\lib\slf4j.jar.
On a side note, you might want to get a program like 7zip, which allows you a convenient (right-click) method for viewing the contents of .zip and .jar (etc) files. That way, you'll be able to find those classes that you can't find otherwise.
Hope that helps—I'm still new to java.

Trouble installing Kyoto Tycoon - Java. Maven failing

I've downloaded Kyoto Tycoon via:
hxxps://bitbucket.org/EP/kyototycoon-java
When running mvn install I get plenty of warnings telling me it couldn't find several files:
http://pastebin.com/znpJ3d5n
When I first started running the install I was getting a lot of failures and no errors. After blindly going around and trying to install things separately, the output now looks like this. I have no experience with Maven so editing the pom.xml file is out of the question. I've tried using the ignore tests and compiling, and I get few jar files. This allows me to compile "Example.java" using:
javac -cp .:target/kyototycoon-0.2-SNAPSHOT.jar Example.java
I then try to run the code using:
java -cp .:target/kyototycoon-0.2-SNAPSHOT.jar Example
but I get an runtime error:
Exception in thread "main" java.lang.NoClassDefFoundError: Exception in thread "main" java.lang.NoClassDefFoundError: com/twitter/finagle/Codec
at kyototycoon.SimpleKyotoTycoonClient.<init>(SimpleKyotoTycoonClient.java:16)
at Example.main(Example.java:11)
Caused by: java.lang.ClassNotFoundException: com.twitter.finagle.Codec
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 2 more
I'm assuming this all comes back the the maven install failing, but I'm not sure how to fix it.
Any direction is appreciated. There doesn't seem to be a large support group for Kyoto.
For anyone experiencing this same issue, I found that JAR files I needed were being created. They were being stored in ~/.m2/repository/kyototycoon/kytotycoon/. I created a disgusting looking classpath that included all of these JAR files and this allowed me to compile AND run the Example.java file.
If "editing the pom file is out of the question" I'd strongly recommend steering clear of Maven.
In any case, you can install local jars to your repository if the artifact isn't available from any repository.

Error when trying to see mvn version in cmd

I keep getting this error when trying to enter "mvn -version in the cmd.
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/c
lassworlds/launcher/Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.lau
ncher.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher
. Program will exit.
'cmd' is not recognized as an internal or external command,
This is usually a problem with misconfiguring M2_HOME or M3_HOME. I'm not sure, but I think you can't have both set. Also, do a "which mvn" - apparently some JVM installs will install a mvn in usr/bin.
your maven configure is the problem.
once check your system variables path, MAVEN_HOME AND JAVA_HOME.
IN PATH - %MVN_HOME%/bin and that maven bin path also add in that path.
IN MAVEN_HOME - where your placing the Maven folder that path you add only not bin or lib folders.
IN JAVA_HOME - where you are installed java software that path can place in that directory. This is also not lib or bin folders just only JDK path.
In classpath- you can add just normally lib folder of the maven.
If you are not added the java_home your adding only maven_home that is also some will be raised.
Here i am placing some site url see that one solve your problem.
http://horrikhalid.wordpress.com/2011/01/12/a-simple-tutorial-of-jsf-2-0-eclipse-weld-and-maven-2/
N.S.Reddy

Resources