JAR does not exist or is not a normal file - java

While running the wordcount example in Hadoop, I am facing the following error.
saying "JAR does not exist or is not a normal file:
/usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduceexamples-2.2.0.jar"
My input command was :
hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduceexamples-2.2.0.jar wordcount input output

Just go to that path and check it out if the name is correct or not, the convention may differ by the distribution.
For example, hadoop 3.1.0 has it in the following path:
$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.0.jar

I faced the same problem and problem was with the version number in file. For example, in the installation instructions, the command was:
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.1.jar grep input output 'dfs[a-z.]+'
While the version I'm working with was 3.1.3 so what worked for me was:
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar grep input output 'dfs[a-z.]+'

Just check whether all the dependencies are included in your jar file.
Try something like this.
hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduceexamples-2.2.0-jar-with-dependencies.jar wordcount input output

Since .jar path can differ from distribution to distribution it's hard to say the exact path and obviously, you can cd into each directory and check, but you ever imagine there is an easy way. Just execute the following command and it will list all the jar files named hadoop-mapreduceexamples-2.2.0.jar with the exact location,
find . -name hadoop-mapreduceexamples-2.2.0.jar
Or if you do not know the name of the .jar file you can try this,
find . -name *.jar

I faced this problem same, beacause I am in /opt/module/hadoop-3.1.3/wcinput directory.
When cd /opt/module/hadoop-3.1.3 , and then try this again :
hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar wordcount wcinput wcoutput.
it worked.

Related

Code runs but doesn't open when converted to .jar file? [duplicate]

I want to execute my program without using an IDE.
I've created a jar file and an exectuable jar file. When
I double click the exe jar file, nothing happens, and when I try to use the command in cmd it gives me this:
Error: Unable to access jarfile <path>
I use the command: java -jar Calculator.jar
How I created the jar:
Right click on project folder (Calculator)
Select
Click on Java Folder and select "Exectuable Jar File", then select next
Launch Configuration: Main - Calculator
Create Export Destination
Hit "Finish" and profit! Well, not really.
I had encountered this issue when I had run my Jar file as
java -jar TestJar
instead of
java -jar TestJar.jar
Missing the extension .jar also causes this issue.
Fixed
I just placed it in a different folder and it worked.
[Possibly Windows only]
Beware of spaces in the path, even when your jar is in the current working directory. For example, for me this was failing:
java -jar myjar.jar
I was able to fix this by givng the full, quoted path to the jar:
java -jar "%~dp0\myjar.jar"
Credit goes to this answer for setting me on the right path....
I had this issue under CygWin in Windows. I have read elsewhere that Java does not understand the CygWin paths (/cygdrive/c/some/dir instead of C:\some\dir) - so I used a relative path instead: ../../some/dir/sbt-launch.jar.
I had the same issue when trying to launch the jar file. The path contained a space, so I had to place quotes around. Instead of:
java -jar C:\Path to File\myJar.jar
i had to write
java -jar "C:\Path to File\myJar.jar"
Just came across the same problem trying to make a bad USB...
I tried to run this command in admin cmd
java -jar c:\fw\ducky\duckencode.jar -I c:\fw\ducky\HelloWorld.txt -o c:\fw\ducky\inject.bin
But got this error:
Error: unable to access jarfile c:\fw\ducky\duckencode.jar
Solution
1st step
Right click the jarfile in question. Click properties.
Click the unblock tab in bottom right corner.
The file was blocked, because it was downloaded and not created on my PC.
2nd step
In the cmd I changed the directory to where the jar file is located.
cd C:\fw\ducky\
Then I typed dir and saw the file was named duckencode.jar.jar
So in cmd I changed the original command to reference the file with .jar.jar
java -jar c:\fw\ducky\duckencode.jar.jar -I c:\fw\ducky\HelloWorld.txt -o c:\fw\ducky\inject.bin
That command executed without error messages and the inject.bin I was trying to create was now located in the directory.
Hope this helps.
None of the provided answers worked for me on macOS 11 Big Sur. The problem turned out to be that programs require special permission to access the Desktop, Documents, and Downloads folders, and Java breaks both the exception for directly opened files and the permission request popup.
Fixes:
Move the .jar into a folder that isn’t (and isn’t under) Documents, Desktop, or Downloads.
Manually grant the permission. Go to System Preferences → Security and Privacy → Privacy → Files and Folders → java, and check the appropriate folders.
I had a similar problem and I even tried running my CMD with administrator rights, but it did not solve the problem.
The basic thing is to make sure to change the Directory in cmd to the current directory where your jar file is.
Do the following steps:
Copy jar file to Desktop.
Run CMD
Type command cd desktop
Then type java -jar filename.jar
This should work.
Edit: From JDK-11 onwards ( JEP 330: Launch Single-File Source-Code Programs )
Since Java 11, java command line tool has been able to run a single-file source-code directly. e.g.
java filename.java
If you are using OSX, downloaded files are tagged with a security flag that prevents unsigned applications from running.
to check this you can view extended attributes on the file
$ ls -l#
-rw-r--r--# 1 dave staff 17663235 13 Oct 11:08 server-0.28.2-java8.jar
com.apple.metadata:kMDItemWhereFroms 619
com.apple.quarantine 68
You can then clear the attributes with
xattr -c file.jar
It can also happen if you don't properly supply your list of parameters. Here's what I was doing:
java -jar test#gmail.com testing_subject file.txt test_send_emails.jar
Instead of the correct version:
java -jar test_send_emails.jar test#gmail.com testing_subject file.txt
This worked for me.
cd /path/to/the/jar/
java -jar ./Calculator.jar
For me it happens if you use native Polish chars in foldername that is in the PATH.
So maybe using untypical chars was the reason of the problem.
sometime it happens when you try to (run or create) a .jar file under /libs folder by right click it in android studio. you can select the dropdown in top of android stuio and change it to app. This will work
My particular issue was caused because I was working with directories that involved symbolic links (shortcuts). Consequently, trying java -jar ../../myJar.jar didn't work because I wasn't where I thought I was.
Disregarding relative file paths fixed it right up.
In my case the suggested file name to be used was jarFile*.jar in the command line. The file in the folder was jarFile-1.2.3.jar . So I renamed the file to jarFile. Then I used jarFile.jar instead of jarFile*.jar and then the problem got resolved
It can happen on a windows machine when you have spaces in the names of the folder. The solution would be to enter the path between " ".
For example:
java -jar c:\my folder\x.jar -->
java -jar "c:\my folder\x.jar"
To avoid any permission issues, try to run it as administrator. This worked for me on Win10.
I know this thread is years ago and issue was fixed too. But I hope this would helps someone else in future since I've encountered some similar issues while I tried to install Oracle WebLogic 12c and Oracle OFR in which its installer is in .jar format. For mine case, it was either didn't wrap the JDK directory in quotes or simply typo.
Run Command Prompt as administrator and execute the command in this format. Double check the sentence if there is typo.
"C:\Program Files\Java\jdk1.xxxxx\bin\java" -jar C:\Users\xxx\Downloads\xxx.jar
If it shows something like JRE 1.xxx is not a valid JDK Java Home, make sure the System variables for JAVA_HOME in Environment Variables is pointing to the correct JDK directory. JDK 1.8 or above is recommended (2018).
A useful thread here, you may refer it: Why its showing your JDK c:program files\java\jre7 is not a valid JDK while instaling weblogic server?
For me it happen because i run it with default java version (7) and not with compiled java version (8) used to create this jar.
So i used:
%Java8_64%\bin\java -jar myjar.jar
Instead of java 7 version:
java -jar myjar.jar
I had a similar problem where TextMate or something replaced the double quotes with the unicode double quotes.
Changing my SELENIUM_SERVER_JAR from the unicode double quotes to regular double quotes and that solved my problem.
this is because you are looking for the file in the wrong path
1. look for the path of the folder where you placed the file
2. change the directory cd in cmd use the right path
I use NetBeans and had the same issue. After I ran build and clean project my program was executable. The Java documentation says that the build/clean command is for rebuilding the project from scratch basically and removing any past compiles. I hope this helps. Also, I'd read the documentation. Oracle has NetBeans and Java learning trails. Very helpful. Good luck!
Maybe you have specified the wrong version of your jar.
I finally pasted my jar file into the same folder as my JDK so I didn't have to include the paths. I also had to open the command prompt as an admin.
Right click Command Prompt and "Run as administrator"
Navigate to the directory where you saved your jdk to
In the command prompt type: java.exe -jar <jar file name>.jar
Keep the file in same directory where you are extracting it. That worked for me.
This is permission issue, see if the directory is under your User.
That's why is working in another folder!
Rename the jar file and try
Explanation :
yes, I know there are many answers still I want to add one point here which I faced.
I built the jar and I moved it into the server where I deploy (This is the normal process)
here the file name which I moved already existed in the server, here the file will override obviously right. In this case, I faced this issue.
maybe at the time of overriding there can be a permission copy issue.
Hope this will help someone.
Have you tried to run it under administrator privoleges?
meaning, running the command in "Run As" and then select administrator with proper admin credentials
worked for me
I was trying this:
After giving the file read, write, execute priviledges:
chmod 777 java-repl.jar
alias jr="java -jar $HOME/Dev/java-repl/java-repl.jar"
Unable to access bla bla..., this was on Mac OS though
So I tried this:
alias jr="cd $HOME/Dev/java-repl/ && java -jar java-repl.jar"
This did not work "Unable to access jarfile"
"C:\Program Files\java\jdk-13+33-jre\bin\javaw.exe" -jar "C:\Program Files\Maxim Integrated Products\1-Wire Drivers x64\ OneWireViewer.jar"
This does work
"C:\Program Files\java\jdk-13+33-jre\bin\javaw.exe" -jar "C:\Program Files\Maxim Integrated Products\1-Wire Drivers x64\OneWireViewer.jar"
The difference is the single space in front of OneWireViewer.jar not withstanding that it is surrounded with quotes and even has other spaces.

Can't specify class path in Java

I have a Test.jar file with ru.package.Tester class in it. When I run the following command in the directory with my jar:
java -classpath /path/to/current/directory ru.package.Tester
I get the following error message:
Could not find or load main class
I'm running on OS X
upd: When I put my jar file into /Library/Java/Extensions, it all works without specifying -classpath.
You need to give path to jar
java -classpath /path/to/current/directory/your.jar ru.package.Tester
could you please check your ~/.bash_profile - what does it contain . I too faced the similar issue on my mac yesterday and got it resolved.
Forget about the classpath. By default, Java looks for the classes directly in the directory. If you want to run a jar, you must tell Java to do so:
java -jar your.jar
Please check manifest file. it must contain main class name in manifest.

Stanford-NLP: Could not find main class error

This question seems to have been answered a few times (What does "Could not find or load main class" mean? and https://stackoverflow.com/a/16208709/2771315) but for some reason none of the shared methods are working.
What I've done so far.
1) Navigated to the directory containing the CoreNLP source files in terminal: ~/Downloads/CoreNLP-master/src
2) Selected one of the packages as a test case e.g. executed the command java -cp "*" -mx5g edu.stanford.nlp.sentiment.SentimentPipeline -file foo.txt (as per the docs, http://nlp.stanford.edu/sentiment/code.html)
I've tried variations of the above by altering the classpath -cp condition and setting it using set CLASSPATH = $CLASSPATH=~/Downloads/CoreNLP-master/src but can't seem to get a result. Does anyone know what I'm doing wrong? If I were to hazard a guess, I think that there is something wrong with the classpath but I'm not sure what.
The classpath should point to the classes, not the source files. If you're using the GitHub version of the code, you can set the classpath to be:
-cp ~/Downloads/CoreNLP-master/classes:/path/to/corenlp/models.jar
You can find the most recent version of the CoreNLP models at: http://nlp.stanford.edu/software/stanford-corenlp-models-current.jar (warning: >200MB file)
If you have one of the corenlp releases, you should set your classpath to:
-cp /path/to/corenlp.jar:/path/to/corenlp/models.jar
For example:
export CLASSPATH=stanford-corenlp-3.9.1.jar:stanford-corenlp-3.9.1-models.jar
Both the corenlp jar and the models jar should show up in the zipped release of the code (e.g., from http://nlp.stanford.edu/software/corenlp.shtml)
This worked perfectly fine for me.
java -cp "../*" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file test.txt
Run this command while you are in the classes directory.
You are trying to run the program, instead of compiling it.

What does "Error: Could not find or load main class org.apache.hadoop.util.RunJar"?

I am trying to run an example as it is pointed in Hadoop in Action book page 15.
this is the command that needs to be run :
bin/hadoop jar hadoop-*-examples.jar
but I get this error
"Error: Could not find or load main class org.apache.hadoop.util.RunJar"
It seems like a classpath issue or something. Can someone point out some guideline ?
Actually I am not able to run any of hadoop commands like version, fs, jar ... and so on .. !
NOTE: I am using windows.
[Edited]
Okay, i was reading too fast, you mentioned you were not able to run hadoop fs commands as well. I guess you might miss a few congifurations or haven't start the services at all. Try following this tutorial step by step.
you will need to pass in the class name, for example:
bin/hadoop jar hadoop-*-examples.jar org.apache.hadoop.examples.WordCount [input] [output]
It is probably so late answer, but any way.
Just check that HADOOP_PREFIX environment variable is set correctly (points to your hadoop installed directory).
you need check your environment variable HADOOP_PREFIX=/path/to/hadoop
Setting the HADOOP_CLASSPATH as follows in your ~/.bashrc worked for me:
export HADOOP_CLASSPATH=$(cygpath -pw $(hadoop classpath)):$HADOOP_CLASSPATH
As described in documentation: http://hadoop.apache.org/docs/r2.6.5/hadoop-project-dist/hadoop-common/SingleCluster.html
You have to set HADOOP_PREFIX pointing to your hadoop installation folder.
This is an example script to start in stand-alone mode:
#!/bin/bash
cd /etc/hadoop-2.6.5/
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
export HADOOP_PREFIX=/etc/hadoop-2.6.5
mkdir input
cp etc/hadoop/*.xml input
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.5.jar grep input output 'dfs[a-z.]+'
cat output/*

bin/hadoop jar hadoop-0.20.0-examples.jar wordcount /tmp/gutenberg gutenberg-output

I'm testing the Hadoop following this "Running Hadoop On Ubuntu Linux (Single-Node Cluster)" tutorial.
There is no output after running this command:
bin/hadoop jar hadoop-0.20.0-examples.jar wordcount /tmp/gutenberg gutenberg-output
If there is an error I will see something, however I see nothing. So, what should I do?
Is it an error, or something wrong with configuration?
Please give me your suggestion.
From the Wiki it looks like the second parameter gutenberg-output is the output file. Have you checked the contents of this file? The example is given in a file rather than output to the console.

Categories

Resources