I have run into a spot of trouble configuring my paths in OSX 10.9.3
To give some context, the issues started when Maven was causing issues referring to my Java version as 1.7, from stackoverflow i took the advice of simply updating my JAVA_PATH
I ran "which java" which gave me:
/usr/bin/java
SO I ran:
export JAVA_HOME=/usr/bin/java
However "man -v" and "java -version" both now complain:
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/bin/java//bin/java
What I am confused about is that blogs, posts and people are saying check .profile and .bash_profile or .bashrc, only .profile exists on my machine, and nothing seems to take effect there. The only joy I have is setting paths in /etc/paths
So my question has a few part, how do I get my original java path back? Where are these "export" paths set or where can i find this reference to JAVA_HOME and lastly, despite defining "JAVA_HOME=/usr/bin/java" is it returning the Error that claims the path is "/usr/bin/java//bin/java"
Any help would be good
JAVA_HOME should be set to the name of the directory that contains the bin directory that contains the Java executables (in particular, java itself).
Assuming you do have a /usr/bin/java directory, it probably contains a jre subdirectory that contains the bin directory that contains java and related executables.
So you should probably be setting JAVA_HOME to /usr/bin/java/jre rather than /usr/bin/java.
On the side note: its a bit awkward place to put your java tbh. I would put it in usr/lib/java
Related
I am trying to extract a jar file from Matlab code using javac from Library Compiler (java package).
I have set JAVA_HOME to:
C:\Program Files\Java\jdk1.7.0_71
and added to PATH:
C:\Program Files\Java\jdk1.7.0_71\bin.
When I enter java -version in my console, I get java version jdk1.7.0_71 and running javac -version shows jdk1.7.0_71.
However, it seems that matlab could not find javac, thus, I am not able to compile my .m code into a .jar file. When I tried to compile .m code I got the following:
Error: An error occurred while shelling out to javac (error code = -1).
Unable to build executable.
Executing command: ""C:\Program Files\Java\Java\jdk1.7.0_11\bin\javac" -verbose - classpath "...\MATLAB\R2014a\toolbox\javabuilder\jar\javabuilder.jar" -d "...\features_extraction\for_testing\classes" "...\features_extraction\for_testing\features_extraction\Class1.java" "...\features_extraction\for_testing\features_extraction\Features_extractionMCRFactory.java" "...\for_testing\features_extraction\Class1Remote.java" "...\for_testing\features_extraction\package-info.java""
This is the directory of my java bin folder and javac.exe exists : ...\Java\jdk1.7.0_71\bin\bin\javac? I found this link for compatibility between Java and Matlab2014a(which is my version) here. What should I check in order to correctly link Matlab to Java? A few days ago Matlab was working correctly with Java.
In my PATH I noticed the existence of the following path: C:\ProgramData\Oracle\Java\javapath in which there are three wrong shortcuts to java.exe, javac.exe, and javax.exe. When I type in matlab console getenv JAVA_HOME I am getting C:\Program Files\Java\jdk1.7.0_11 while when I wrote version -java I got: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode. When I write javac in matlab console I am getting: Undefined function or variable 'javac'.
When I try to built C++ library I got a similar issue: Error: An error occurred while shelling out to mbuild (error code = -1).
Unable to build executable.
EDIT: Does the absence of the proper MCR counts in my case?
You said
getenv JAVA_HOME I am getting C:\Program Files\Java\jdk1.7.0_11 while when I wrote version -java I got: Java 1.7.0_11-b21
try to use setenv in MATLAB, doc here http://www.mathworks.com/help/matlab/ref/setenv.html
setenv('JAVA_HOME','C:\Program Files\Java\jdk1.7.0_71');
setenv('PATH','C:\Program Files\Java\jdk1.7.0_71\bin');
Following from the answers in this link
http://www.mathworks.com/matlabcentral/answers/131639-matlab-deploytool-not-working-fails-while-building
seems like you have to install JDK 1.7.0_11-b21, which is the one your MATLAB version is compatible with for compiling into jar. Also, after installing that specific version, you should modify the JAVA_HOME and PATH environment variables. Try that to see if it helps.
I was having a very similar problem with my installation.
I set the environment variable (press > type env > Enter) JAVA_HOME (under "User variables") to my JDK home directory (not the bin folder) without any trailing \ or ;.
The problem occurs because MATLAB cannot execute javac properly, however, in order to work out exactly what MATLAB is trying to execute (which is not working) we need to use the command window and not the Library Compiler.
It appears you have already done this but for completeness I will add the process here for others.
To find what MATLAB executes, click "Open log file" and copy the entire first line.
Paste the first line in the MATLAB command window and add -v to the end.
Press enter to run the command and note the "Executing command:" that is printed to the screen.
Once you have the "executing command" that MATLAB returns for you, check the first path in that command and make sure it matches your javac file.
In your original post you have done this and posted
C:\Program Files\Java\Java\jdk1.7.0_11\bin\javac
a path which contains \Java\Java, if this isn't a typo then it may be a problem as it is not the default Java installation path. You also say after that your installation is at
...\Java\jdk1.7.0_71\bin\bin\javac
which contains \bin\bin and is also not the default java bin install directory, perhaps another typo?
If the path to javac matches exactly you could try copying and pasting the "executing command" into your OS's command window (+R > cmd > Enter) and looking for errors. By doing this we can remove ourselves from the MATLAB installation and if errors still exist it likely has nothing to do with MATLAB.
To see if the same problem could be caused by other environment variables I removed every other path to a java installation (keeping JAVA_HOME) in my environment variables. MATLAB uses the absolute path to the java installation and so it was still able to compile with javac using only the JAVA_HOME environment variable.
I want to use elastic search with my PHP application.
after running service install command , I am getting fallowing error.
C:\elasticsearch-0.90.10\bin>service install
JAVA_HOME points to an invalid Java installation (no java.exe found in "C:\Progr
am Files (x86)\Java\jdk1.7.0_25\bin"). Existing...
Open up and Look into the service.bat file:
It searches for:
%JAVA_HOME%\bin\java.exe
hence your %JAVA_HOME% should not include bin in it.
A workaround if you do not have privileges to set up the environmental variables:
open the service.bat file,
a) Remove the line:
if NOT DEFINED JAVA_HOME goto err
b) Replace %JAVA_HOME% with your java jdk path, something like: C:\Program Files\Java\jdk1.7.0_51
Note: This is just a workaround which works all the time.
from your error message we can see your JAVA_HOME points to
C:\Program Files (x86)\Java\jdk1.7.0_25\bin
while it should point to
C:\Program Files (x86)\Java\jdk1.7.0_25
I think the error message is fairly descriptive , you should look in this folder
is java.exe there ? If not then your JAVA_HOME environment variable to point to the correct installation
heres a page showing how to do that
https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
1st hit on google.
Either JAVA_HOME points to the wrong location or you don't have Java installed. Check and see if there's an install of Java in the location specified.
Also note that the JAVA_HOME variable should point to the root of the Java install not the /bin folder. This is being added by the program you're executing.
To change the JAVA_HOME variable to test further use the following in the command prompt:
set JAVA_HOME=c:\xxxx
Once you've established the correct value to use this can be permanently changed in Control Panel>>System>>Advanced System Settings>>Advanced>>Environment Variables
set JAVA_HOME=C:\Program Files (x86)\Java
Above must fix the issue, I came across the same issue while installing the elastic search.
i gave a try by giving "bin" part of path but it did not work, so i just give the top folder "java" in path, it worked.
Just to add my own experience.
i was setting JAVA_HOME using tab autocompletion.
It ends up something like "C:\Program files...:" and it didn't work saying that it cannot find the java program. I solved typing the JAVA_HOME path in the set command without using tab completion. The problem was probably related to the " in the env variable
I will try and keep this as concise as possible since I need to get this figured out quickly. Back when I setup Titanium Studio 2.1.1.201207271312 on Linux Mint 13 64-bit system, I had all kinds of problems installing a version of Java Titanium liked. In the end I Think I used the instructions here to get it working.
Now all these months later when I try to compile an app for Google Play I get this dreaded error:
[ERROR] Program launch failed. Unable to locate Java VM. Please set JAVA_HOMenvironment variable.
[ERROR] Unabled to prepare JavaScript for packaging. Error code 4.
Checking the java alteranatives on my system I get this:
'update-alternatives --query java
Link: java
Status: auto
Best: /usr/lib/jvm/java-6-sun/jre/bin/java
Value: /usr/lib/jvm/java-6-sun/jre/bin/java
Alternative: /usr/lib/jvm/java-6-sun/jre/bin/java
Priority: 63
Slaves:
java.1.gz /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz
Alternative: /usr/lib/jvm/java-7-oracle/bin/java
Priority: 1
Slaves:
java.1.gz /usr/lib/jvm/java-7-oracle/man/man1/java.1.gz
I have the following set in my .profile
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre/bin/java
export PATH=$PATH:/usr/lib/jvm/java-6-sun/jre/bin/java
But still I get the error in Titanium. I have tried numerous different variations of my .profile file, but with no luck.
I really need to work this out quickly. Does anyone have any ideas?
EDIT: Solved
I seem to have worked the proper paths, here is how my .profile now reads:
JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export JAVA_HOME
PATH=$PATH:/usr/lib/jvm/java-6-sun
export PATH
.profile is usually processed by sh, while .bash_profile is processed by bash (and instead of .profile when present). Try following sh compatible format (which has bitten me before when mucking with .profile files):
JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_HOME
PATH=$PATH:/usr/lib/jvm/java-6-sun/bin:/usr/lib/jvm/java-6-sun/jre/bin
export PATH
I Corrected to what I usually use, I was just echoing your values, but I should have been more careful. I usually have JDK and JAVA_HOME is supposed to be the base for it and then I add bin for both JDK and JRE. If you compiling then you may need the JDK and not just the JRE.
I seem to have worked out the proper paths, here is how my .profile now reads:
JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export JAVA_HOME
PATH=$PATH:/usr/lib/jvm/java-6-sun
export PATH
Recently, when trying to compile java programs from the command prompt, I get this error:
Error: Cannot find or load main class com.sun.tools.javac.Main
I have the latest versions of the JDK and JRE, and I still get the error.
Here is what I type in the command line:
C:\Java_Source_Codes>javac hi.java
Can anyone help?
(Here is my java code)
public class hi{
public static void main(String[] args){
System.out.println("hello, world!");
}
}
You have a number of issues, Kumar mentioned the compilation issue, but that's not the immediate problem that's stopping you.
You have JAVA_HOME set to a Java Runtime environment, but are finding javac on the system PATH. When this happens, you can call javac from the command line, but when javac detects the JAVA_HOME environmental variable, it loads its libraries from a directory that doesn't include the "java tools", tools.jar. The contents of "java tools" includes the classes that implement the compiler.
You probably have JAVA_HOME set to something like /some/path/here/jre. Assuming that the jre directory is the embedded JRE shipped with your JDK, you probably should have set the JAVA_HOME to /some/path/here.
You need to have your PATH variable set up with a path to Java tools needed for compilation.
You need to have these folders in Path system variable.
D:\Program Files\Java\jdk1.6.0_32\jre;D:\Program Files\Java\jdk1.6.0_32\bin
Just replace D:\Program Files\Java with the folder you have installed Java on your computer.
Also, if you are using any other verion of JDK, replace jdk1.6.0_32 with your own.
This is due to some issue with your PATH.
Quick guess is you have multiple version of java on your PATH
Set the Path to the bin directory of the jdk in your system..
Try typing java -version on the cmd to see if your Java path is properly set.
Mine is..
C:\Program Files\Java\jdk1.7.0\bin
I had the similar problem but found a simple solution that might work in your case too.
My problem was I simply made a new folder in c directory to save my *.java files (like a test folder) and set my PATH to ...jdk\bin folder.
When I try to compile in cmd I got the same error main class not found.
So i went to environment variable and in user variable, where I saw my CLASSPATH pointing to same folder. So I changed my CLASSPATH to folder having my files in my case C:\test and the problem was solved.
Hope this helps.
I have Ubuntu 10.10 with java already installed. I am able to execute java command from any folder. I supposed that could be because I had java Classpath setted. But neither JAVA_HOME nor CLASSPATH are setted.
If I look at /etc/environment content I can see that PATH is setted to /usr/bin/ (among others). As 'which java' returns /usr/bin/java, is that the reason why I can execute java from anywhere? If not, why is it?
You can execute java because the command is on your path.
echo $PATH
will show you which directories are searched, in which order to find a particular program. Since /usr/bin is on your path, when you type java it will eventually look at /usr/bin/java. Note that in many systems this is a symbolic link (a file that points to another file) so /usr/bin/java often points to /etc/alternatives/java (which is also a symbolic link that points to the real executable).
Where the environmental variable JAVA_HOME comes into play is in tools and programs that check for JAVA_HOME and act on it instead of relying on the path. In most modern Linux systems, the work done by the alternatives subsystem replaces the earlier (more problematic) JAVA_HOME technique. That said, you might want to set JAVA_HOME anyway, should you encounter a tool that demands it.
One reason why JAVA_HOME is not as popular as it could be is that to access JAVA_HOME you need to run a shell, and not everyone wants to wrap every single Java item in a shell command.
Yes, if java binary (or a link to it) is on a folder that is listed on the path then you can execute java without specifying the path to it (for example /usr/local/java/latest/bin/java -jar x.jar)
JAVA_HOME and CLASSPATH have nothing to do with system path.
JAVA_HOME allow other software (or scripts) to know where to look for java installation.
CLASSPATH tells java where to look for classes (.class files resulting of compiling .java files).