Error: Could not find or load main class - Command line - java

I read a hundred posts related to this but nothing seems to help my case.
A strange thing is happening with my commands. To start off, for the current task I need to be using textbook libraries from an algorithms book and the installer from that book also sets up Java SE 7. I have Java 8 JDK installed on my pc from before (if that is info worth knowing). So, for example, when I am running programs which involve methods from that textbook library I write java-algs4.
Last night there was something wrong with the Path variables and I wasn't able to compile anything so I was setting some of those and then things started working. However, today, when I tried running java helloworld (after doing javac helloworld.java) I got the error mentioned in the title. Moreover, I could successfully run another class file in the same directory but after I ran it once, I couldn't anymore and got the error again. This seems like black magic to me!
When I echo %CLASSPATH% I get the current directory.
Here are my current java-related PATHs set in my environment variables if this is of any help. The algs4 is the one from the textbook.
In User variables - PATH
C:\Users\Denitsa\algs4\bin;C:\Users\Denitsa\algs4\java\bin;c:\Program Files\Java\jdk1.8.0\bin;C:\ProgramData\Oracle\Java\javapath;
In System variables - PATH
_C:\ProgramData\Oracle\Java\javapath;C:\Users\Denitsa\algs4\java\bin; C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_31\bin;_
I would really appreciate your help with this, been trying to solve this for a while now!
Thanks.

I was trying to run it without the capital letters in the name. Now it is working.

Related

The error I get Which checking Apache Pig Version "Error: Could not find or load main class C:\java\lib\tools.jar"

I have my java working properly and also the environment variable is also set for java jdk 1.8.0_261
But when I run the pig -version its shows Error: Could not find or load main class C:\java\lib\tools.jar.
I have also checked the java folder in lib for tools.jar and it is there.
Also the Apache Pig configuration is also correct in pig.cmd
My Hadoop and MapReduce all are working fine with no error.
Your installation is broken, or you have messed up a shell script. That error cannot really mean anything else.
When invoking java.exe, you can either pass a jar file, via java -jar C:\foo.jar, or a classpath + fully qualified class name: java -cp C:\foo.jar;C:\bar.jar com.foo.fullyqualified.ClassName.
That error means you've passed C:\java\lib\tools.jar in the position of that classname. That will fail to run on any system and regardless of installations: C:\java\lib\tools.jar is a file path, not a fully qualified class name. That tools.jar exists in that location is immaterial: It's as if I told you: "I searched for the book titled "Can of Paint" on your bookshelf and I can't find it", and you going: "That's bizarre, because (pointing at the cans of paint on the shelf in the garage), there are cans of paint right here". Java isn't treating that as a path to look up; it is treating it as a class name to search for on the classpath.
Note that this trivial invocation:
java.exe C:\lib\tools.jar
produces the exact error you are observing and that is the correct behaviour of java (because the right way to run it is either java -jar C:\lib\tools.jar or more likely java -cp C:\lib\tools.jar;. com.foo.YourApp. The fix is to.. not invoke java incorrectly like this.
Reasons
Perhaps pig.cmd is broken. The image you pasted does not include the actual call to java.
Perhaps java is broken. Does java.exe work at all? Make some test file, compile it, run it. Does that work?
Perhaps the script is trying to start the jar by letting windows do it (so, double clicking it, or in a script, start foo.jar, which will then end up checking the HKLM registry section for .jar, and then checking the key there for how to start it, and if you've manually edited that, that would break things: You then presumably set it for e.g. java %1 which is broken (it'd have to be java -jar %1).
pig -version doesn't invoke the pig.cmd you think it invokes, but something else.
Something in pig.cmd starts another script. Then that script is broken, or isnt the script pig.cmd thought it was, etc.

Can anyone interpret what these instructions mean? Trying to install a JVM to a mac

Please bear with me. I'm a biology student trying to perform Species Distribution Modeling of certain plant species in Australia using R Studio (specifically using a Maximum Entropy model) and I have a limited understanding of the command line.
In order to do this, I need to use the rJava package in R Studio. While the installation seems to work, when I run the command:
library(rJava)
I get this warning message:
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
So I found this tutorial online:
https://github.com/s-u/rJava/issues/86#issuecomment-261039681.
Towards the bottom of the page, the user gwarnes-mdsol gives a step-by-step guide to fixing this problem using my mac's command-line. I am supposed to install Java, uninstall any existing rJava packages, and then run a few lines of code that he wrote out. However, I can't seem to get past this step. What does he mean when he says to add the export command to the the filepath he supplied? Am I supposed to fill in portions of this code with filepaths that are specific to my computer?
# Add the following lines to /Users/<userid>/.bashrc:
# Set JAVA_HOME so rJava package can find it
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)/jre
I'm not sure where to begin with this. I've tried downloading a JDK (jdk-11.0.6_osx-x64_bin.tar.gz) and renaming it JAVA_HOME but then I don't know where to put it in my computer. I don't know where to find a .bashrc file. How can I run this code properly?
Any help is greatly appreciated!

Text garbling in compiling Java at Cygwin

I'm a university student in Japan, and I can't speak English well, but let me ask one question.
I attempted to start Java and installed Java jdk1.8.0_171 including javac and java.
Then, I set PATH at Windows10, and succeeded in compiling one java file.
However, when I attempted another file, Cygwin showed me an error message and it was broken, so called text garbling.
I don't mind that language in Cygwin will be English, so please teach me how to solve this problem.
よろしくお願いいたします。

How to resolve system cannot find the path specified error in windows 10 Java?

I am brand new at Java and have been trying to write "Hello World!". I have gotten far enough to install java with jdk and I've see countless videos on the environmental variables and setting those up with the paths. In the CMD when I write Java or Javac, it works fine, but trying to do step #4 (compiling) on this step by step site: http://www.codejava.net/java-core/how-to-write-compile-and-run-a-hello-world-java-program-for-beginners
I get completely stuck. Its when I am trying to "change the directory" that it tells me that the system cannot find the path.. Right now I'm at a complete loss.
Any suggestions on what I need to do? I am happy to post screen shots if that will assist as well.
Java error picture:
When running the command in the prompt window, Windows is looking at the PATH environment variable.
Make sure that the bin directory of the JDK is referenced in that variable.

Combine CPLEX and JAVA

Java - CPLEX
For a seminar at university I need to program a model with java.
Since it is a maximization problem I also need to involve CPLEX methods. Therefore I successfully installed CPLEX on my Mac OS X Version 10.5.8.
To combine CPLEX and Eclipse (I also tried it with Netbeans) I connected my current project with the CPLEX library (Properties>Library>Add Library).
Eclipse recognizes the library because the methods aren't underlinded. Additionally I committed the following argument to my run configurations:
-Djava.library.path=/Users/myname/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx
When I try to run an exemplary code (that is valid) I get the following error:
java.lang.UnsatisfiedLinkError: /Users/myname/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx/libcplex1260.jnilib: no suitable image found. Did find: /Users/myname/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx/libcplex1260.jnilib: unknown required load command 0x80000022Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
at ilog.cplex.Cplex.CPXopenCPLEX(Native Method)
at ilog.cplex.CplexI.init(CplexI.java:6594)
at ilog.cplex.CplexI.<init>(CplexI.java:629)
at ilog.cplex.IloCplex.<init>(IloCplex.java:11067)
at ilog.cplex.IloCplex.<init>(IloCplex.java:11082)
at Knapsack.buildModel(Knapsack.java:54)
at Knapsack.main(Knapsack.java:122)
java.library.path must point to the directory containing the CPLEX shared library
try invoking java with java -Djava.library.path=...
could you please be so kind to help me, i don't know any more what to do.
Thank you for an answer
I found this question when having the same problem. followed the advice from the internet and found that I was putting the -Djava.library.path argument in the wrong place... You should really double check not only the paths but also if you put your arguments in the correct place and correctly typed. It seems silly but happens :)
Anyway, in my case, I am using NetBeans, I went to:
Project Properties
Run
in the VM Options text field:
-Djava.library.path=/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx
I hope this will help you
Make sure you closely followed the steps described in 1 for setting up eclipse.
Make sure the environment variable DYLD_LIBRARY_PATH is set in the environment eclipse is running in. See 2. First check if DYLD_LIBRARY_PATH is set. Second try to execute your java program via terminal.

Categories

Resources