error when installing Java EE SDK on Linux - java

I did have JDK installed, and also put $JDK_HOME/bin on my PATH. However, I still have problem to install Java EE. Could you guys give me some hints? Thanks.
dav#Bruno:~$ ls
[some stuff...]
33511405_3645.jpg glassfish stuff
bea hplip-3.11.12-plugin.run temp
bin hpscan001.png Templates
C03_08.txt java_ee_sdk-6u4-jdk7-linux.sh Tomcat
c4c jdk1.7.0_10 Ubuntu One
[some stuff2...]
dav#Bruno:~$ echo $PATH
/home/dav/jdk1.7.0_10/lib:/usr/share/java:/home/dav/jdk1.7.0_10:/home/dav/jdk1.7.0_10/bin:/home/dav/Fluent.Inc/bin:/home/dav/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/dav/jdk1.7.0_10/lib:/usr/share/java
dav#Bruno:~$ sudo sh java_ee_sdk-6u4-jdk7-linux.sh
Could not locate a suitable jar utility.
Please ensure that you have Java 6 or newer installed on your system
and accessible in your PATH or by setting JAVA_HOME
dav#Bruno:~$

I think the problem you're facing is that the PATH variable you're looking at is set for the user 'dav', but because you're sudoing the sh command, the PATH changes to that of root, which probably doesn't contain the JDK.
I think you should try explicitly setting the JAVA_HOME environment variable, try running:
sudo JAVA_HOME=/home/dav/jdk1.7.0_10 sh java_ee_sdk-6u4-jdk7-linux.sh

in case someone still gets frustrated over this:
("Could not locate a suitable jar utility.
Please ensure that you have Java 7 or newer installed on your system
and accessible in your PATH or by setting JAVA_HOME")
First of all make sure you are not using "sudo" to install java ee.
when you use sudo you use a different environment (root, with not necessarily the same
environment variables). in this case (ee installation) sudo is not required.
In other (which ever) cases when root access is required make sure the required user/system variables are set on system level, not (just) on user level.
to set variables at system level instead of user level define the variables in a system level script, i.e. /etc/profile or /etc/profile.d
otherwise, if you are not using SUDO trying to install jee, and still have this "JAVA_HOME not set"-problem, try this:
the cause seems to be the JAVA_HOME variable that can not be found by the install script.
therefore adjust ~/.bashrc to define JAVA_HOME.
JAVA_HOME of course has to point to your oracle java (se/jdk) installation. If you haven't installed it, that's the first thing to do. JAVA_HOME should point at the root directory of the installation (not to the bin directory in it), i.e.:
export JAVA_HOME=/usr/local/jdk1.7.1_02.
Next change path like so:
PATH=$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
keep the faith
don't let frustrations get the better of you (perhaps making you take it out on your colleagues or loved ones :o )
don't allow stress to build up too much. take a break in time to watch a funny video or
take a stroll to the coffee machine, or have a little chat with that cute person a couple of desks away from you.

You'll need to create an update alternative for the "jar" executable like:
sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.6.0/bin/jar" 1
Note: You may need to use appropriate path in your case.

Related

How to run JMeter through CMD from jdk/bin directory?

I want to run JMeter test plans from a UNIX server where env variables for java is not set. Its a test server and I dont have access to set that. We have different JDK versions and all are sitting in directories. I need to run my JMeter TestPlans on this server. I went to JDK /bin folder and tired to execute the below command
$ {jmeter-path}/bin/jmeter -nt testplan.jmx -l testresult.jtl
but this says
./bin/java: not found
But if I do simple java -version it shows the version result.Is that something that JMeter needs specifically the java env variable set or it wont run ? I dont have permission to set and I want to run the testplan using the JDK/JRE from its directories. A help would be appreciated. Thanks in advance!
UPDATE:
I think I could work around this by editing the jmeter script file as suggested in the one of the comments. Since my requirement was running the JMeter from a specific server, I could achieve this by editing the JAVA_HOME variable value in the script.
JMeter looks for java executable in system PATH so you have 2 options:
Add bin folder of your JDK or JRE to PATH, something like:
PATH=$PATH:/location/of/your/jbk/bin && export PATH && {jmeter-path}/bin/jmeter -nt testplan.jmx -l testresult.jtl
Or if you have java in PATH just run ApacheJMeter.jar like:
java -jar {jmeter-path}/bin/ApacheJMeter.jar
You might also want to use jmeter.sh wrapper script instead of jmeter, it has some logic regarding java binary location
More information: Get Started With JMeter: Installation & Tests
The official JMeter Getting Started documentation says this:
To install a release build, simply unzip the zip/tar file into the directory where you want JMeter to be installed. Provided that you have a JRE/JDK correctly installed and the JAVA_HOME environment variable set, there is nothing more for you to do.
Based on the symptoms that you reported, I think that you have not set JAVA_HOME correctly. It should be set to an absolute path to your Java installation's top directory.

Maven installation issues: JAVA_HOME should point to a JDK not JRE?

I'm super new to CS and very unfamiliar with UNIX/Bash vocab.
I'm currently trying to install Maven, and I made a few mistakes by copy pasting old installation instructions (with incorrect version numbers) and now the whole process is so messed up. I first tried to follow the given instructions on the website, that didn't work, then I tried a few other ones, and now I'm worried that I'm left with a mess by following different sets of instructions.
I've reached a point now where if I type in mvn -version I get the following:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Originally, my JAVA_HOME was set to jdk-install-dir, which still gave me the above error message. I tried redownloading the jdk (version 13.0.1) from Oracle, dragged that file to my home directory, and unzipped it. Then I set my JAVA_HOME to that unzipped file, jdk-13.0.1.jdk, and updated my PATH variable. After all this, I'm still getting this same error message, and I'm not sure what to do.
For the reference, here are what some relevant environment variables are set to (I didn't include irrelevant info from PATH):
~ echo $JAVA_HOME
jdk-13.0.1.jdk
~ echo $PATH
/usr/local/apache-maven/apache-maven-3.6.3/bin:/opt/apache-maven-3.6.3/bin:jdk-install-dir/bin:/usr/local/apache-maven/apache-maven-3.3.9/bin:/opt/apache-maven-3.6.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/allyson/apache-maven-3.6.3/bin:/Users/allyson/apache-maven-3.6.3/bin:jdk-12.0.1.jdk/bin:/Users/allyson/apache-maven-3.6.3/bin:JDK-13.0.1.jdk/bin
~ echo $M2
/usr/local/apache-maven/apache-maven-3.6.3/bin
~ echo $M2_HOME
/Users/allyson/apache-maven-3.6.3
One thing I'm curious about: for the M2 and M2_HOME variables, is it supposed to be that one is in my home directory (/Users/allyson) and one is for /usr/local?
OK, take a deep breath, and we'll walk through this. Each of these environment variables has a purpose, and once you understand what those purposes are, this makes a lot more sense. Mixing tutorials is not necessarily a problem, but you'll want to understand what you're doing, rather than just blindly copy values from the internet.
JAVA_HOME is intended to identify to the system environment where to find a java runtime environment. It needs to be set to the full path of where your JDK has been installed. On windows, this might be C:\Program Files\Java\jdk-13.0.1. On a Linux system, you have a bit more flexibility. Common locations might be /opt/java/jdk-13.0.1 or /usr/local/java/jdk-13.0.1. If you installed your JDK somewhere else, then you need to use that path instead. The message NB: JAVA_HOME should point to a JDK not a JRE refers to a common mistake when installing maven -- maven requires a JDK, not a plain JRE. This error is so common that any time JAVA_HOME points to a folder that isn't a JDK, it prints this warning (even if the folder in question isn't actually a JRE).
M2_HOME is supposed to be set to the full path where maven is installed (i.e. the place where you unzipped it). This more or less helps maven "find itself" if it should need to for whatever reason. Strictly speaking, this one isn't necessary. (It's not set on my system, and maven works fine for me). It's mostly a convenience for setting the next environment variable.
M2 is the full path to the folder where the maven executable is. This will almost always be $M2_HOME/bin, but it's certainly possible to do weird things, and this will let you work around those situations. Obviously, this won't work if you didn't specify $M2_HOME. This one isn't strictly necessary, either, and is mostly a convenient way of setting up the next one.
PATH is where your Linux system looks to find programs to run when you type their name on the command line. For ease of use, you'll want to make sure that the maven and java executables are included somewhere in the : delimited list. Most Linux distributions already have a default PATH set up for you in a shell resource file of some kind. You'll want to refer to their documentation for how to add another entry to the path, but a common idiom would be PATH=$PATH:$M2 (which would append the value of $M2 to the value of $PATH and then store the result back into PATH. If you didn't set up $M2 or $M2_HOME, you'll need to do something else.
So, TL;DR, if you installed your JDK in /opt/java/jdk-13.0.1 and unzipped maven into /opt/maven/apache-maven-3.6.3, your bear minimum working values are:
export JAVA_HOME=/opt/java/jdk-13.0.1
export PATH=$PATH:$JAVA_HOME/bin:/opt/maven/apache-maven-3.6.3/bin
And if you wanted a complete set
export JAVA_HOME=/opt/java/jdk-13.0.1
export M2_HOME=/opt/maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin:$M2
It's worth noting that most Java IDEs will include a GUI for setting up maven and Java within the IDE (the settings will typically only work within that IDE). It's often much easier for beginners to get up and running that way.
$JAVA_HOME should be a full path, not the dir name.
scream#kafka1:~$ echo $JAVA_HOME
/opt/java/jdk-11.0.5/
scream#kafka1:~$
I'm working on Ubuntu 20, and my own issue was about the jdk version located in the JAVA_HOME variable, which wasn't the right version. This was my trip around that issue:
First, What is the JAVA_HOME value?
$ echo $JAVA_HOME
$ /usr/lib/jvm/jdk-11.0.10
Next question/step, where is the Java app pointing to?
(Source: https://stackoverflow.com/a/42706056/2373421)
$ java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'
java.home = /usr/lib/jvm/jdk-11.0.12
So, the JAVA_HOME variable wasn't keeping the right value. Let's change that:
$ export JAVA_HOME=/usr/lib/jvm/jdk-11.0.12
The test outcome is right now:
$ mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /opt/apache-maven-3.8.1
Java version: 11.0.12, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-11.0.12
I'm doing this for future me's bc after all the links in StackOverflow, the solution was to check mvn.cmd file on C:\Program Files\Maven\apache-maven-3.6.3\bin...
On line 52 it sets the JDK, but it didn't had the "/bin" where my OpenJDK 15 stored the java.exe
This fixed the issue on Windows 11 but it could serve as an idea for other OS. Hope that it helps!

working with the command prompt in Java

I've been learning java on my own and I've come to a point where I need to pass arguments from the command prompt. I had previously been using Netbeans, which has become a bit of a crutch, but I want to learn how to program using notepad and the command prompt. I am running Windows 8.1. I downloaded the JDK 7 to my C:\ directory. I tried typing "java -version" and "javac -version" to check it out (as my book says to do) but it tells me "'java' is not recognized as an internal or external command, operable program or batch file." It says the same when I try javac. I do this from C:\ and from C:\Java> and get the same result. I uninstalled Netbeans, thinking maybe it was interfering somehow ... still not working. The book I'm using says it covers Java 7.
I don't understand why it doesn't work. Is there some compatibility issue with Java 7 and win 8.1? My java 7 is update 71 or 72. Did this update change something and now arguments are passed differently? Can anyone help me out? Thank you.
You need to download the JDK (if you don't already have it) and add the location to the end of your PATH. In a single command line session you can do this with PATH=%PATH%;<jdk location> where <jdk location> is the bin folder of the jdk.
Some installs of java manage environment variables and some do not. It appears yours has not. or you have not installed it correctly.
many applications understand JAVA_HOME, so you should set that to the root of the installation in your environment variables.
You will also need to add the bin folder to your path.
Generally, when using windows, you can install a windows exe version, which will manage all of this for you. Other installations just copy themselves to the c drive and expect java applications to know where to look.
Go to System environment variable. Select Variable PATH. Click on edit button. Append a ; after current value of Variable value. Copy jdk's bin folder path. In my PC it is "C:\Program Files\Java\jdk1.8.0_20\bin" without quotes. Then paste jdk's bin path. Copy jre's bin folder path. In my PC it is "C:\Program Files\Java\jdk1.8.0_20\jre\bin". Append a ; then paste jre's bin folder path. Click OK.
Download the JDK from this page. Run the installer.
Open the Command Prompt. Try it. It works. Yay!
If you use the full path to your java.exe, you dont need to set up any PATH and JAVA_HOME:
c:\> cd \work
c:\work> c:\java\bin\java.exe -cp classes\ your.Main
If your book does not use the normal JDK installers it really is supposed to explain that. (However it is normal behaviour for any executable).
(The above example asumes you compile into c:\work\classes\your\Main.class and your JDK is installed (installer does the unpack) in C:\java (typically you would use default locations like C:\Program Files\Java\jdk1.8.0\bin\java.exe).

Set JDK path in linux

Something really weird occurs. When I type in:
which java
the output is like:
/private/me/jdk1.8.0_20/bin/java
and when typing in:
echo $JAVA_HOME
the output is:
/usr/java/jdk1.6.0_24
I want to use 'jdk1.6.0_24' and I change all the things in '/etc/profile' and '~/.bashrc' to point it to 'jdk1.6.0_24', such issue still existed. The java I use is still 1.8. Why?
I am pretty sure you need to update-alternatives:
sudo update-alternatives --config java
and select java 1.6.0
Try updating your path as follows:
export PATH=/usr/java/jdk1.6.0_24/bin:$PATH
don't use export PATH=$PATH:/usr/java/jdk1.6.0_24/bin unless you uninstall first the "default" java (if you use this then the java binary in /usr/bin will be found first, which is not what you want).
There is a caveat on this: the binaries in /usr/java/jdk1.6.0_24/bin will be found before than the ones in the rest of the path, which is harmless because you only have java-related binaries on /usr/java/jdk1.6.0_24/bin
caveat #2: make sure you are not redefining PATH after this line or in another script
Go to your home, and show hidden file, then you will find the file .bashrc. Edit and go to the end of the file, then add
export PATH=$PATH:/usr/java/jdk1.6.0_24/bin
$PATH means the current path, in order to append the new value
Then, you will use jdk1.6.
Each time you write java -version, you will find the most recent version (jdk1.8), but your program will use jdk1.6

setting issue of JAVA_HOME and JAVA_PATH

I have been using Eclipse to develop java program on a windows 7 machine. It works. I also typed "java" from the command prompt, it also shows the help message. In other words, I think Java was correctly installed on this machine. However, when I open the "environmental variable" setting on this machine, I cannot find either "JAVA_HOME" setting and "JAVA PATH" setting. What is the problem of this?
Java also copies java.exe and javaw.exe under C:\Windows\System32, there's where your java is running from.
You can confirm that by using where commmand:
On my win7 machine:
>where java.exe
C:\Windows\System32\java.exe
Some environment variables are defined at machine level and some are defined (and overwritten) at user account level. Just do following in windows cmd prompt:
c:\echo %PATH% or just type c:\path
and verify the output.
You can also verify java home path by writing a simple Test class like following:
public class Test {
public static void main(String[]s){
System.out.println(System.getProperty("java.home"));
}
}
There are multitudes of links to be fond on Google regarding how to solve this in Windows. These environment variables typically do not get setup by default when installing java.
Here are some 10 second finds with with answers:
How to set java_home on Windows 7?
Setting the JAVA_HOME Variable in Windows
Installing Java on Windows 7 and setting-up the JAVA_HOME
Check you PATH variable in Environment Variables. It must be set to jreInstallation/bin. Windows does not pick up java command from JAVA PATH, it picks java command from PATH variable.
Also note that once you install JDK, path is not set by installation to jdkInstallation/bin, you need to set it up explicitly.So unless you set the path to jdkInstallation/bin, javac wont be recognized.
Check your path variable in windows environmental variables. At least Java path should be there .
It may looks like this.
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0\bin
You should set path and classpath variables.
Here's the link you can follow for step by step instructions.
[http://abodeqa.wordpress.com/2012/08/11/how-to-set-path/][1]
With Java, Groovy, Git, Heroku, Maven, and many other projects, what I always do is this:
1. Unzip the software package into a directory, for example:
C:\AeroFS\Java\jdk1.7.0_25
C:\AeroFS\Groovy\groovy-2.0.5
2. Create a HOME variable, such as JAVA_HOME or GROOVY_HOME that points to the
above locations.
3. Put these in your default system path by editing your PATH variable and
adding %JAVA_HOME%\bin and %GROOVY_HOME%\bin to the end of your PATH. In
the case of JAVA_HOME only, you might want to put it at the beginning of
the PATH to override the java.exe that rests in the WINDOWS directory
location.

Categories