Change java symlink - java

My Windows 8 command prompt doesn't see java anymore. I found that in C:\ProgramData\Oracle\Java\javapath located wrong symlink that I can't change. When I try change I got error:
Problem with Shortcut
The name 'C:\Program Files\Java\jre1.8.0_45\bin\javaw.exe' specified in the Target box is not valid. Make sure the path and file name are correct.
When I try to create shortcut I have message:
Windows can't create a shortcut here.
Do you want the shortcut to be placed on the desktop instead?
[Yes] [No]
How to solve this problem?

Here is how you solve this problem :
Delete the original symlinks. All the three of them, I think there
are three.
Do not create a shortcut. Shortcut and Symlinks are not same.
Open a command prompt in the same directory and create new Symlinks using the "mklink" command and point it to your JDK install.

If you use java from the command prompt chances are high that you need to have correct JAVA_HOME variable set as well. Some tools depend on it.
To do it - edit the system environment variables:
Add JAVA_HOME and point it to the install path of java version you want
you could also use symbolic link for the folder
In "Path" variable find "C:\ProgramData\Oracle\Java\javapath;" and replace it with %JAVA_HOME%\bin

First Uninstall the java from your system, after remove the oracle folder in C:\ProgramData. Then again reinstall the java. Next click on javac.bat in bin folder of jdk.After check with command prompt like, >javac it will display all the options.then it's working perfectly...
I think it's duplicate of
How to make a symlink in Java when running in Linux?

Related

How to get java command running?

When working with any command line (windows-cmd, git bash, ..), no Java commands are working.
I executed java -version and nothing happens. I can type again.
I have set my JAVA_HOME variable to C:/Users/myName/Java/jdk1.8
and I have also added %JAVA_HOME%\bin to my Path variable.
It's not, that the command does not get recognised. It's just that nothing happens.
I could probably run the java.exe command directly, but I wanna fix the env variable.
Can someone help?
Best regards
Try this (Windows):
Locate your JDK/JRE binary - Usually the path for your JDK/JRE bin (On Windows) is:
Your OS Drive(C or D etc):\Program Files\Java\jdk[version]\bin. After you've located it, Copy your path to your clipboard.
Search for "Environment Variables" on windows.
Create a new User variable name it (usually named "JAVA_HOME") and copy your path as a value.
Now in System variables locate a variable named "Path" and add the same value set in JAVA_HOME.
Close and then reopen the CMD.
If this solution does not work, reinstall java. You can uninstall through:
Control Panel -> Programs -> Under Programs and Features -> Uninstall a program.

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.

Run a jar file only with jre [duplicate]

When trying to check the current version of Java in which I am running, I received the error "java is not recognized as an internal or external command, operable program or batch file.".
I am running Windows 7 OS and have downloaded the latest JDK and felt I may have accidentally deleted the java from machine as before I was able to check the Java version using the command "java -version".
What software must I download to get Java working on my machine again?
EDIT:
I have managed to get Java running from my cmd again after ensuring all environment variables pointed to the current Java SDK.
You need to configure your environment variables, JAVA_HOME and PATH.
JAVA_HOME must contain the path to java, and you should add %JAVA_HOME%\bin to PATH
Alternatively, you can simply add to your PATH the whole path to the bin folder, without the JAVA_HOME variable, however, this makes a little more annoying when you need to have more than one java version on your machine (that way you only need to change JAVA_HOME and don't even bother with PATH)
For Windows 7:
Right click on My Computer
Select Properties
Select Advanced System Settings
Select the Advanced tab
Select Environment Variables
Select Path under System Variables
Click on the Edit button
In Variable value editor paste this at the start of the line
C:\Program Files\Java\jdk1.7.0_72\bin;
Click Ok then Ok again
Restart command prompt otherwise it won't see the change to the path variable
Type java -version in the command prompt.
Notes on Step 8:
The version of java in this may be different from the one used here -- this is only an example.
There will probably be other values in the path variable. It is really important that you don't delete what's already there. That's why the instructions say to paste the given value at the start of the line -- this means that you don't remove the existing value, you just put java before it. This also fixes any problems you'd be getting if an other version of java is also on the path.
Notes on Step 6:
This sets the path for the computer, not for the individual user. It may be that you're working on a computer which other developers also use, in which case you'd rather set the user variables, rather than the system variables
It sounds like you haven't added the right directory to your path.
First find out which directory you've installed Java in. For example, on my box it's in C:\Program Files\java\jdk1.7.0_111. Once you've found it, try running it directly. For example:
c:\> "c:\Program Files\java\jdk1.7.0_11\bin\java" -version
Once you've definitely got the right version, add the bin directory to your PATH environment variable.
Note that you don't need a JAVA_HOME environment variable, and haven't for some time. Some tools may use it - and if you're using one of those, then sure, set it - but if you're just using (say) Eclipse and the command-line java/javac tools, you're fine without it.
1 Yes, this has reminded me that I need to update...
Assume, Java/JDK is installed to the folder: C:\Program Files\Java:
Follow the steps:
Goto Control Panel → System → Advanced system settings → Advanced → Environment variables (Win+Pause/Break for System in Control Panel)
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\bin, press OK:
In the System variables section double click on Path
Press New and write C:\Program Files\Java\bin, press OK:
In Environment variables window press OK
Restart/Run cmd.exe and write: java --version:
Search environment variables.
open the "edit the system environment variables".
then click on "environment variables".
Under "User variables" click on "Path" then "Edit".
Find your Java path and click "Edit".
then paste the path of your java installation folder.
Mostly you can find it on a path similar to this.
C:\Program Files\Java\jdk-12.0.2\bin
Then click OK.
now in the start menu, type cmd.
open the command prompt.
type
java -version
If you did it right,it should show something like this.
For me its start working after putting ,: in the starting of the system variable path :--
My solution was to put same value (path to JDK bin folder) in JAVA_HOME and Path
In my case, PATH was properly SET but PATHEXT has been cleared by me by mistake with .exe extension. That why window can't find java or anything .exe application from command prompt. Hope it can help someone.
This problem is on Windows 8.
First copy your Path of java jdk - e.g. C:\Program Files\Java\jdk1.7.0_51\bin.
Right on the My Computer Icon on the Desktop and Click Properties.
Select 'Advanced System Settings' in the left pane.
Under 'Advanced' tab, select 'Environment Variables' at the bottom.
In System Variables, select 'Path' Variable and edit it.
Paste the path and add a ';' at the end - e.g. C:\Program Files\Java\jdk1.7.0_51\bin;
I had the same problem. Just Install the exact bit of java as of your computer. If your PC is 64 bit then install 64 bit java. If it is 32 bit then vice versa :)
Not sure why, but in my case, the reason was because I was running Anaconda terminal instead of the CMD.
After I use CMD and update the path settings as mentioned by all comments above the issue solved on my side.
In case you are using a laptop and do not have the Pause\Break button.
For windows 10 users with 20h2 and above:
1 WIN → type "About your PC" → scroll at the bottom → Advanced system settings → Environment variables or WIN+R → shell:::{bb06c0e4-d293-4f75-8a90-cb05b6477eee} to open Classic System Properties → on the left side → Advanced system settings → Environment variables
Also for Windows 10 and Windows 7:
1 WIN → This PC → properties → Advanced system settings → Environment variables
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\jdk-15.0.2\bin, press OK
I have taken steps 2-4 from Vijay Bhatt
There is a bit faster way to set a system variable. Run a console (terminal) as an administrator.
General command synax to add a new variable:
setx variableName value /M
In our example, we would need to set it as
setx JAVA_HOME "C:\Program Files\Java\jdk-15.0.2\bin" /M`
Like this:
/M - flag specifies to set the variable in the system environment.
After command execution, you should see the message:
SUCCESS: Specified value was saved.
How can I check that it is added?
Close your active terminal;
Open your favorite terminal;
Type java -version.
You should see something similar to this:
Notice:
User variables can be created w/o having a root (administrator privileges), whereas to create System variable; You need to open a console as a root.
I have used C:\Program Files\Java\jdk-15.0.2\bin as an example, in your case, it could be different from mine.
I opened a new command prompt in Windows 10 after updating the environment variables without closing the old one(To have my commands handy and lazy to type again)
Still, the new cmd window was referring to the previous version of Java.
Then once I closed the all cmd prompts that ran with admin privileges, the new java version was getting reflected.
I corrected my path variable but command prompt need to Restart otherwise, it won't be able to verify the change to the path variable. May be helpful for someone like me. so
"restart command prompt"
Restart the command prompt before checking the version of JDK installed. I spent 02 days on it until my problem resolved when I restarted the command prompt before checking javac - version, javac etc.
if you have cygwin installed in the Windows Box, or using UNIX Shell then
Issue bash#which java
This will tell you whether java is in your classpath or NOT.
If you have set the environment variables (JAVA_HOME and PATH) under user variables, command prompt (run as administrator) will not identify java. For that you need to set environment variables under system variables.
Try this:
System variables:
PATH = /bin folder of your jdk install
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm
Just some extra information for people that have still problems,
instead of editing the path variable of java, delete that part of the path(only the java!!)
and make a new variable pointing tpo the jdk/jre.
this seemed to work for me.

The JAVA_HOME environment variable is not set

I'm trying to make my first app using Phonegap and I got this while running in command
C:\USERS\KTR\DESKTOP\PHONEGAP\LIB\ANDROID\BIN>create C:\Users\KTR\Desktop\Demoap
p com.example.Demoapp Demoapp
The JAVA_HOME environment variable is not set.
Set JAVA_HOME to an existing JRE directory.
Remember to also add JAVA_HOME to the PATH variable.
After updating system variables, open a new command window and retry.
Any help would be greatly appreciated
Thank you
You have to do two things to get it fixed.
Firstly go to My Computer right click open properties and open Advanced System Setting and then open Environment variables. Open the Path variable and insert a semicolon at the end and add the path of your bin folder of your jdk it will be something like C:/Program Files/Java/ Jdk X.Y/bin save and close it.
Secondly create a new system variable named JAVA_HOME and in its value write C:/Program Files/ Java/ Jdk X.Y save and close and now retry by writing the create command
P.S find the version number go to your java folder and copy those version number hopefully this will help
You need Java on your computer. See how to install and configure java http://docs.oracle.com/cd/E19509-01/820-3208/inst_cli_jdk_javahome_t/
Hope this will help

Even when I defined the class path, javac is not recognizing it

I am using Windows 7 and 8 in my PC .
I have installed jdk 7 and created class path for bin as it should be. But when I enter javac in the command prompt, it throws an error:
`javac is not recognizing as internal and external`.
I have searched for a solution in many websites but nothing could solve my problem.
Would you please help me and suggest where my mistake could be?
You need to set the environmental variables. Run sysdm.cpl from run dialog box to open advanced system properties.
In the environmental variables, add a new one like in this dialog.
Name : JAVA_HOME
VALUE: C:\Program Files\Java\jdk1.7.0_21\
Now edit the value of the PATH variable and add ;%JAVA_HOME%\bin\; at the end of it's value.
Now, restart your system and you can run java related commands from command prompt.
also set path in your *System variables:path=c:/..../jdk/bin/;c:/..../JRE/bin;.;
user Variables:CLASSPATH=c:/..../jdk/bin/;c:/..../JRE/bin;.;
Double check your system variable "Path" on System Properties appending %PATH_TO_JDK%\bin. Don't forget to restart the command prompt after.
It is path not classpath - -till your bin folder
and restart cmd

Categories

Resources