IntelliJ can't find tools.jar without sudo - java

I'm trying to run IntelliJ on Ubuntu 14.04. I've read this question but the solutions don't apply -- I've definitely got the JDK installed rather than the JRE. When I try to run idea.sh, I get the error message:
'tools.jar' seems to be not in IDEA classpath. Please ensure JAVA_HOME
points to JDK rather than JRE.
JAVA_HOME is set to /etc/java-7-openjdk. Eclipse (in the form of Eclim) has no problem finding it. javac -version prints javac 1.7.0_55.
However, if I run sudo ./idea.sh, IntellJ launches fine. What am I missing?

I had the exact same problem half an hour ago. Took me exactly that half hour to fix it, this is how it worked for me:
Short version:
add
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
to your .bashrc, source it and you are fine.
Explanation:
After installing the JDK in Ubuntu there are multiple folders on your disk.
The root folder is
/usr/lib/jvm/java-7-openjdk-amd64/
under which the aforementioned /jre -Folder resides.
The whole problem is, that the jre/lib -Folder does not contain the tools.jar - File searched by the IDE.
Only the /usr/lib/jvm/java-7-openjdk-amd64/lib - Folder does.
To get everything working you have to specify /usr/lib/jvm/java-7-openjdk-amd64 as JAVA_HOME.
Setting /usr as your JAVA_HOME wont solve the problem as that is symlinked to /etc/alternatives which is symlinked to our old friend the /jre-Folder.
I hope this helped you!

In the 64 bit Debian 7, I solved the problem by adding this two lines of code in idea.sh under the /path/to/intellij-folder/bin/
export IDEA_JDK=/path/to/jdk/
export JAVA_HOME=/path/to/jre
And I hope it will solve the problem in Ubuntu.

It turns out JAVA_HOME was set wrong, I needed to set it to:
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
to get it working. I'm not sure why this hadn't caused me any problems before.
EDIT: This setting makes Maven angry (although Maven via IntelliJ works fine). For future readers, I believe the correct setting is:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/

you can change your current java version as follows
alternatives --config java
alternatives --config javac
but before them you need to install your newly installed JDK in alternatives properly:
alternatives --install /usr/bin/java java [new-jdk-path]/bin/java 120 --slave /usr/bin/rmiregistry rmiregistery [new-jdk-path]/bin/rmiregistry --slave /usr/bin/keytool keytool [new-jdk-path]/bin/keytool --slave /usr/lib/tools.jar tools.jar [new-jdk-path]/lib/tools.jar
alternatives --install /usr/bin/javac javac [new-jdk-path]/bin/javac 120 --slave /usr/bin/jar jar [new-jdk-path]/bin/jar --slave /usr/bin/rmic rmic [new-jdk-path]/bin/rmic

Related

How to find the JRE location to use the system JRE in eclipse

I'm trying to set up a java project to use openjdk-11 and all the answers I have found so far have me going in circles. I'm using ubuntu 20.04, so I used the command 'sudo apt install openjdk-11-jre'. The installation seemed to be successful but now I can't seem to figure out the file path to the installed JRE. I thought it would be under /user/lib/jvm/java-11-openjdk-amd64 somewhere. When I point eclipse to that location and try to search for a JRE however it doesn't find anything.
I have found lots of examples with info on how to install but nothing about how to track down the exact file path. Any help would be greatly appreciated.
Update
While I was able to find the JRE location, the root problem turns out to be eclipse. I forgot I had an older version (4.6) open since that is what the project was originally using. Once I switched over to 4.18 I was able to add the java 11 JRE.
Using which will give you /usr/bin/java which won't help as it will be a symlink. You need something like
readlink -f $(which java)
you can use the following:
update-alternatives --list java
will gives you something similar to the below:
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

error while trying to use lombok.jar in ubuntu

I was initially using vs-code where everything was working.
I think eclipse doesnt understand I am using lombok, so I downloaded lombok.jar from here
while trying to run java -jar lombok.jar i get the following error -
eclipse -
java version and paths
the issue, as pointed out by #stdunbar was conflicting versions
i was initially trying
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-16.0.1/bin/java 1
but it didnt work. what worked was
sudo update-alternatives --config java
i selected /usr/lib/jvm/jdk-16.0.1/bin/java there, and now it works
Just ensure that your JAVA_HOME and java -version point to the same Java. For that make sure you have updated JAVA_HOME variable in "/etc/profile" or "/etc/environment" or "~/.bashrc", all these files should be updated if they point to different JAVA folders.

Can't specify SDK in Intellij on Linux

I am running IntelliJ IDEA 2017.1.6 Pro on a Linux (Ubuntu) machine and, it will not let me select an SDK for any Java project.
Whenever I start up the program and go to "Create a New Project" Java has no SDKs available. If go to new and try to specify where my JDKs are installed (I have a few) it always fails with the same error:
I've tried specifying the locations:
/usr/lib/jvm/
/usr/lib/jvm/java-11-openjdk-amd64/
/usr/lib/jvm/java-8-openjdk-amd64/
/usr/lib/jvm/openjdk-11/
/usr/lib/jvm/jdk-14.0.2/
/usr/lib/jvm/default-java
/usr/lib/jvm/java-1.11.0-openjdk-amd64
/usr/lib/jvm/java-1.8.0-openjdk-amd64
(these last three are all just symlinks)
I know I have a JDK installed for my default Java version. I can compile and run code via command line:
justin#stephanie:~/temp$ ls
HelloWorld.java
justin#stephanie:~/temp$ javac HelloWorld.java
justin#stephanie:~/temp$ ls
HelloWorld.class HelloWorld.java
justin#stephanie:~/temp$ java HelloWorld
Hello, World!
The output of readlink -f $(which java) is /usr/lib/jvm/java-11-openjdk-amd64/bin/java (same location for javac exectuable).
Everything I've looked at online suggest that I should just be able to select /usr/lib/jvm/java-11-openjdk-amd64 as my Java SDK but it is failing. I feel like I must be misunderstanding something essential here as I don't know why this isn't working.
Any help would be useful, I've never used IntelliJ before (I've always been an Eclipse user) and it is very frustrating I can't even create a project in it after a couple hours of trying to mess around with it.
1. Please try first with a newer version of IntelliJ, preferably the most current one (currently this is 2020.2)
2. I had the same problem (with version 2020.2 on my Kubuntu system) and fixed it by simply downloading and installing the SDK via IntelliJ.
The /usr directory is mounted at /var/run/host.
You should find your jdk under /var/run/host/usr/lib/jvm.

Unix Java path variables is being reset

I have a machine running RHEL 6. Currently JDK 7 is installed. For ElasticSearch I need to move to JDK 8. SO i copied the JDK 1.8 to /opt/. THen ran the below steps.
update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 100
update-alternatives --config java
Did the same thing for Javac as well.
Then did the below changes to Environment variables
export JAVA_HOME=/opt/jdk1.8.0_45/
export PATH=/opt/jdk1.8.0_45/bin:...
In setting path, i copied the existing path, removed the jdk7 entries and added the entire path again.
After this when i ran java -version i got 8. But on restarting the shell, it reverted back to 1.7!!!
So i checked internet and found that i need to update the /etc/profile file
So added below two entries..
export JAVA_HOME=/opt/jdk1.8.0_66/
export PATH=/opt/jdk1.8.0_66/bin:$PATH
But even afer this, the JDK 1.7 is being append to teh Path variable.
Any pointers on how i can move to JDK 1.8
I got it working. There was a script file inside /etc/profiles.d/. It was named as jdk.sh. There the JAVA_HOME and PATH was being set. I changed this to the jdk1.8 and the issue was solved. Thanks. i got a comment from Stackoverflow about the way to set the Path using script inside profile.d folder. So searched there and found the script. Took me 2 hours to figure this out... – Shabin Hashim

Installing Jetty on Ubuntu, getting com.sun.tools.javac.Main is not on the classpath

I'm trying to install Jetty on Ubuntu 11.04 and I'm about to pull my hair out. I'm running into a classpath issue. I start Jetty with start.jar, setting JAVA_HOME to point to the JDK.
/usr/share/jetty$ export JAVA_HOME=/usr/lib/jvm/java-6-sun
/usr/share/jetty$ java -jar start.jar
[...]
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-sun-1.6.0.26/jre"
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:127)
...
Notice that it's ignoring the JAVA_HOME I set, and using the jre. I've also tried this:
java -classpath /usr/lib/jvm/java-6-sun/lib/tools.jar -jar start.jar
Same error message. It's not finding, com.sun.tools.javac.Main, and that's in tools.jar.
Down in the guts of Jetty, when it's trying to compile my .jsp's, it's using Ant, and that's doing some kind of classloader tricks, I'm guessing. Does anyone know what the secret is to telling this cranky software where my tools.jar file can be found??
Note that I've gotten the same error with the sun jdk and openjdk and, yes, I do have the JDK installed, not just the JRE.
The way apt-get installs java, the java binary that's part of the JDK points into the JRE. Like this:
ls -alph /usr/lib/jvm/java-6-sun/bin/java
lrwxrwxrwx 1 root root 15 2011-10-25 18:48 /usr/lib/jvm/java-6-sun/bin/java -> ../jre/bin/java
I'm guessing that Jetty, Jasper or Ant does some trickery to try and find tools.jar based on the location of the java executable, and that's what's failing here.
Any clues are greatly appreciated. Thanks!
Though you're exporting a new JAVA_HOME environment variable, I don't see that you're also exporting a new PATH environment variable. You're probably still picking up the java executable from the original Java home location. Try including export PATH=$JAVA_HOME/bin:$PATH.
Since comments are kinda unreadable on SO, here's the info you asked for:
$ lsb_release -s -c
natty
I installed the sun JDK like so, but remember that the same error occurred with openjdk.
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get -y install sun-java6-jdk
sudo update-alternatives --config java
I'm pretty sure configuring the environment that I run start.jar in is on the wrong track, since I tried pretty hard with that and got nowhere.
Jetty call's Jasper, which calls the Ant task that compiles your JSPs. In the source for Ant's org/apache/tools/ant/taskdefs/Javac.java you can see where it's setting the classpath.
My problem likely has something to do with passing or not passing environment variables or maybe java systems properties down that chain.
An Ugly Solution
Just for laughs, I created a symbolic link from /usr/lib/jvm/java-6-sun/lib/tools.jar to /usr/lib/jvm/java-6-sun/jre/lib/ext. Ugly, huh? But, it works.
You can add tools.jar to the boot classpath of the JVM:
java -Xbootclasspath/p:/usr/lib/jvm/java-6-sun/lib/tools.jar -jar start.jar

Categories

Resources