jar: command not found in Bash - java

I created one jar file in following location: '/usr/local/bin/niidle.jar'
But when I type command as follows:
jar tf /usr/local/bin/niidle.jar
then it shows the following error:
--The program 'jar' can be found in the following packages:
* java-gcj-compat-headless
* gcj-4.2
* sun-java5-jdk
* kaffe
* gcj-4.3
* cacao-oj6-jdk
* openjdk-6-jdk
* fastjar
* sun-java6-jdk
Try: apt-get install <selected package>
bash: jar: command not found
Do you have a solution for this?

Apparently the jar program is not found by the operating system. Have you installed any of the packages containing it, and set up your path correctly?
In order for the OS to find an executable, the path environment variable must include the directory where that program is located. Otherwise you need to specify its full path to access it.

Well, it can't find the jar program. Perhaps your JDK isn't on the path, or you haven't installed one? If you have installed one, try to find where it is, and look in there for the jar program.

Try runnning "java -jar /usr/local/bin/niidle.jar"

On Ubuntu 12.10 The program jar is in /usr/lib/jvm/jdk-[version]/bin
edit the file /etc/environment for add to the path. Close the session and open a new session.

You seems to be using either Debian or Ubuntu. And it is telling you that you did not install one of the packages containing the 'jar' executable. You will have to install one corresponding to the java package you use on your system. In order to know which java package you already have type this : dpkg -l | grep java

If you are like me and you already have everything installed, but you just get the same error when trying to type jar: it should be listed in your PATH.
Run echo $PATH.
If you're like me, it does not contain the entry like this /usr/lib/jvm/jdk1.8.0_66/bin.
Make sure it's not $JAVA_HOME/bin, all variables should be expanded!
If you don't have the entry, but have JAVA_HOME set, run export PATH=$PATH:$JAVA_HOME/bin
See if you got the jar command.
If it does, google about environment variables to set that effect forever.
Have a nice day.

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.

java 'jar' is not recognized as an internal or external command

I'm getting the following error when I try to run the 'jar' command in the command line on windows :
'jar' is not recognized as an internal or external command
The general solution seems to be that I need to add the jdk bin folder to the PATH in environment variables. I have already done this, I added the following to the path variable :
...; C:\Program Files\Java\jdk1.8.0_40\bin\;
Though I'm not sure if having the jdk reside in 'program files' instead of 'program files x86' affects this. I'm on 64 bit windows with 64 bit java.
Thanks
The path should only contain directories where the OS will look for executables. Strip the trailing "\jar.exe" to set your path as:
(old path variables here);C:\Program Files (x86)\Java\jdk1.7\bin
Thanks To : #stevevls
Try using this command:
java -version
If it doesn't work that means you failed to properly add path to jdk.
If it does work, try using:
java -jar
The jar command in command line is used in order to create a JAR file. For example:
jar cf jar-file input-file(s)
See more at: Oracle docs
If you want to run the existed JAR file you should use the java -jar command mentioned by #Aleksandr.
But in your case it looks like you don't have an access to the added directory in your path with JKD binaries so at the beginning try to execute mentioned java --version to check whether you have java in you classpath at all.
Please remember that on Windows you have to restart the console when you change the windows default path. You do not see the changes on the current console.
The x64 version of Java is installed on Program Files. The x86 version is installed on Program Files x86 by default.
Five steps to solve this problem:
check whether in your bin folder jar.exe is availbale or not
check for your environmental setting
download jar file from here http://originaldll.com/file/jar.exe/29248.html and keep in bin folder
now check for jar it will 100% work
keep any jar in your desktop and go to desktop path on cmd prompt and run the command jar xf filename.jar
Now see if it is working

Error: Could not find or load main class, Cassandra

I am trying to build Casandra project on a Centos server. I downloaded the file from here.
http://apache.bilkent.edu.tr/cassandra/2.0.6/
Here is the README.txt file
This short guide will walk you through getting a basic one node cluster up
and running, and demonstrate some simple reads and writes.
* tar -zxvf apache-cassandra-$VERSION.tar.gz
* cd apache-cassandra-$VERSION
* sudo mkdir -p /var/log/cassandra
* sudo chown -R `whoami` /var/log/cassandra
* sudo mkdir -p /var/lib/cassandra
* sudo chown -R `whoami` /var/lib/cassandra
Note: The sample configuration files in conf/ determine the file-system
locations Cassandra uses for logging and data storage. You are free to
change these to suit your own environment and adjust the path names
used here accordingly.
Now that we're ready, let's start it up!
* bin/cassandra -f
As README.txt file suggested I followed these instructions as adapting to my case (I am not root).
tar -zxvf apache-cassandra-2.0.6-src.tar.gz
cd apache-cassandra-2.0.6-src
mkdir -p var/log/cassandra
chown -R `whoami` var/log/cassandra
mkdir -p var/lib/cassandra
chown -R `whoami` var/lib/cassandra
Since I am not root on the server, I can not create my files under /var folder. So, I created new folder var under apache-cassandra-2.0.6-src and put my lib and log files there. Then I followed next instructions from README.txt file.
bin/cassandra -f
However whatever I tried it is no good, I always get this error.
Error: Could not find or load main class org.apache.cassandra.service.CassandraDaemon
How can I fix this problem?
My java version
java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
EDIT:
As an extra informaiton, I tried this instructions on my pc, too. Exactly same thing with README.txt file using sudo and it worked.
I see you have downloaded the source package (apache-cassandra-2.0.6-src.tar.gz), but the instructions you posted seem to assume it is already built.
You need to build the source package before you can use it; there would be a separate set of instructions for that somewhere.
I suspect you'd rather just run it instead of building it from source. You may have meant to download the binary package apache-cassandra-2.0.6-bin.tar.gz instead (note "bin", not "src" -- this is a traditional naming convention when separating binaries from source in downloadable archives). With that package you can just run it right out of the box. For the source package you'd need to follow the build instructions to compile cassandra first.
I also suspect that you downloaded the binary package on the PC side, which is why it worked there.
If you do need to build from source:
Install ant and ant-optional if you do not already have it.
Extract the source archive somewhere, then in the base directory (where build.xml is):
ant release
Make a cup of coffee (the rat task at the end takes forever).
Binary archives will be created in build, and a built distribution can be found in build/dist.
do a export CASSANDRA_HOME=location of cassandra
should work in 2.0.6 i verified just then without setting that variable and after setting those variables.
$ export CASSANDRA_HOME=/usr/local/cassandra/dsc-cassandra-2.0.6
$ /usr/local/cassandra/dsc-cassandra-2.0.6/bin/cassandra
or
$ cd /usr/local/cassandra/dsc-cassandra-2.0.6
$ export CASSANDRA_HOME=
$ bin/cassandra
in fact you can also set CASSANDRA_HOME= in cassandra-2.0.6 directory. set it to empty value if you are executing the export command from the cassandra directory.
Path for CASSANDRA_HOME was incorrect for me. After i set the correct path it ran perfectly.
In the cassandra.yaml configuration file, change the
commitlog_directory
data_file_directories
saved_caches_directory
properties to the path you have specified as they are no longer /var/lib...
You will need to set them to point to wherever the directories actually are.
I faced exact problem, where I wanted to install cassandra in userspace without any sudo privileges. I did the following
In cassandra.yaml I changed the following config to local path
commitlog_directory
data_file_directories
saved_caches_directory
log4j.appender.R.File
Installed the "bin" tar files for the particular OS env and not the "src" file.
Export CASSANDRA_HOME=/userspace/cassandra-2.x
Now it works fine for me.
I faced same issue when I used Jdk 1.8_281 version.
The problem was resolved when I downgraded to jdk 1.8_241 version.

Cannot determine current directory

I am trying to run a .jar file that was created successfully in Netbeans and I am receiving the following error:
Error occurred during initialization of VM java.lang.Error:
Properties init: Could not determine current working directory. at
java.lang.System.initProperties(Native Method) at
java.lang.System.initializeSystemClass(System.java:1070)
The command that I type to run the .jar is
java -jar "/path to the dist forlder/EOPPrototype.jar"
My classpath is as follows:
CLASSPATH=/opt/netbeans-7.1.2/ide/modules/ext/mysql-connector-java-5.1.13- bin.jar:/h/USERS/local/pagola/NetBeansProjects/mylib/dist/mylib.jar:/h/USERS/local/pagola/NetBeansProjects/EOPPrototype/build/classes:.
What am i missing?
I saw the same error when I was trying to call java -version inside a directory, which I already had deleted from another terminal session. Of course in that case java could not determine the current working directory, simply because it didn't exist.
Solution: cd to another directory and run that command again, that works for me.
See explanation here: https://bugs.openjdk.java.net/browse/JDK-8186434
In Fedora 21, I tried calling the "java -version" after an uninstall and it gave the above error. Close all the terminals and open them again and try.
Should work.
I was getting the same error message, but I'm not sure if it was for the same reason as I don't use Netbeans. I use my terminal and compile with ant.
I cd'd to a directory to run a javafile.class file. The file I want to run is part of a bigger package. The directory structure of the package looked something like this: a/b/c/javafile.class. The a, b, and c directories are all part of a larger package.
To run my javafile.class, I cd'd into a and ran the file from there: java b/c/javafile. After I made some changes and recompiled with my ant script, the directory I was in had been deleted and remade by ant. So, when I ran javafile.class again, I got the error you're getting.
I fixed my problem by cding out of the directories that are deleted and remade by ant and then running my javafile.class again.
maybe you did not config java environment on your workstation correctly
the following configurations were what I did in my mac
vi ~/.bash_profile
and add those in it
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
replace
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
with your jdk version
and then run
source ~/.bash_profile
to use these config immediately
then you can check by
java -version
I got the same error -
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.
by just doing 'java -version' (you would think it wouldn't need to bring up a
virtual machine just to answer a simple question like 'what version are you?')
A higher up element (that between the slashes) of the directory path of the pwd
had spaces in it. When I made the current working directory one which from /
downward didn't have any spaces the 'java -version' command got a proper response.
I'm concluding they didn't account for directories with spaces when they
programmed it. But that was version 1.7. I've now loaded version 8 so hopefully
it has been corrected.
I got this error on Mac OS X and this is a genuine error since the directory has vanished. The directory I was when I am executing the commands is <PROJECT DIR>\target.
The problem was I opened two terminals in the other terminal I ran mvn clean install and the target directory from PROJECT DIR got deleted and recreated.
My old terminal from where I was executing Java commands is not in a valid directory.
The file descriptor is invalid since the directory got deleted by Maven.
When I moved back to the parent directory and the changed back to the target directory, the java command started working correctly as expected.
Under CentOS, rhel, SL or SLC? Not an issue under debian/ubuntu.
I found you need to logout of the shell you are using and log back in. The environment is not set up initially correctly for the current shell. After login I see that: java -version will work.
Also ensure that /etc/alternatives/java actually points to something reasonable like:
ls -lisa /etc/alternatives/java
72645 0 lrwxrwxrwx. 1 root root 46 May 27 11:29 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
Just now, i got the same error. because i use java to setreuid/setregid to apache:apache, when i change back to root:root, i changed gid before uid, the real result is root:apache. everything going wrong, such as the error say "java.lang.Error: Properties init: Could not determine current working directory. "
you can check it.
I was having this error in my mac, when I start tomcat from my eclipse. After setting JAVA_HOME and restarting the eclipse, the error is fixed.
You have to install default-jdk first !
sudo apt install default-jdk
only version 11 does not set all the environment correctly
in place of : sudo apt install openjdk-11-jdk
You may get this error if you issue "java -version" or other java command from a read-only directory. For example using openjdk 8 on centos (as non-root user):
cd /usr/bin
java -version
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.

how to run jar file on RHEL5?

I have made a jar file which i tested in windows and it works fine. now i want to test it for red hat enterprise linux 5. but i dont know how to run jar files in rhel5.
i've tried java -jar My.jar but it says bash: java: command not found. i've set JAVA_HOME variable as export JAVA_HOME=/root/jdk1.6.0_21 but still not working.
can anybody tell me how to run jar file in rhel5?
You need to set PATH variable , something like
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
replace /usr/java/jdk1.5.0_07/bin with path to your jdk's bin directory.
The problem is your terminal tries to find java command from the PATH , but it couldn't find it.
Update:
You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
Top tip but slightly off topic.
1) Install your JDK in /usr/local/jdkX.X.X_XX/
2) Create a symbolic link /usr/local/java -> your chosen JDK installation
When you install new versions of java or if you want to revert to an older version, just change the symbolic link.

Categories

Resources