Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Idea under Linux, No such file or directory on main class

I'm running IntelliJ Idea under linux. I have created a project and a module inside it, and in that module I have a class (MyClass.class) and when I'm trying to run it from IDE, I get

ERROR: MyClass.class (No Such file or directory)

Can somebody explain me why IntelliJ Idea doesn't recognize the classes inside my module? I know it should be a problem regarding module settings but I can't figure it out. I'm using Ubuntu 11.10

OK I place here the paths and everything for all to see :)

type : echo $PATH
Result: /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-7-openjdk-i386/bin:/usr/lib/jvm/java-7-openjdk-i386/bin:/usr/lib/jvm/java-7-openjdk-i386/bin

type: echo $JAVA_HOME Result:
/usr/lib/jvm/java-7-openjdk-i386

type: ./idea.sh Result: NOTE: If you have both Sun JDK and OpenJDK installed please validate either IDEA_JDK or JDK_HOME environment variable points to valid Sun JDK installation

like image 453
Aurelian Cotuna Avatar asked Nov 06 '11 22:11

Aurelian Cotuna


People also ask

How do I specify main class in IntelliJ?

Now, there are 2 approaches for running this main method in IntelliJ. Firstly, we can simply run Ctrl + Shift +F10 or Control + Shift + R/D from the main class. IntelliJ will then create a temporary Run configuration.

Does IntelliJ IDEA work on Linux?

IntelliJ IDEA is a cross-platform IDE that provides consistent experience on the Windows, macOS, and Linux operating systems. IntelliJ IDEA is available in the following editions: Community Edition is free and open-source, licensed under Apache 2.0. It provides all the basic features for JVM and Android development.

How do I run IntelliJ on Linux?

Run the IntelliJ IDEA app from the Applications directory, Launchpad, or Spotlight. Run the idea.sh shell script in the installation directory under bin. You can also use the desktop shortcut, if it was created during installation.


1 Answers

Arkde, I have a possible explanation why Jaroslav's solution with JDK7 didn't work for you.

Maybe you had mixed Java versions in various alternatives items, possibly conflicting with the version that environment variables like JAVA_HOME and JDK_HOME point to?

Maybe something points to the /usr/lib/jvm/default-java symlink as the JDK home, and that symlink points to a different version of JDK than intended?

Did you try resetting alternatives for all Java tools to version 7? Like this:

update-java-alternatives --list
# ...see what JDK's are available, choose the one that corresponds to Java 7
# and set it to be the default in alternatives:
sudo update-java-alternatives --set java-1.7.0-openjdk-amd64
# or interactively:
sudo update-alternatives --config java

What do the following commands output on your system?

echo $JAVA_HOME
echo $JDK_HOME
ls -l /usr/lib/jvm/default-java
update-java-alternatives --list
update-alternatives --list java

I had exactly the same problem. I've performed strace on the Idea process and in the log I saw it trying to open several .class files without the path to them specified - like open("SomeClass.class", O_RDONLY) = -1 ENOENT (No such file or directory) - no path to the project output directory and to appropriate package.

So I've apt-get installed JDK 7 along JDK 6:

apt-get install openjdk-7-doc openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless openjdk-7-jre-lib openjdk-7-source

In Ubuntu 11.10 Oneiric, OpenJDK 6 isn't removable if you want OpenJDK 7. JDK 7 is dependent on JDK 6...

So I've:

  1. updated alternatives configuration as specified above,
  2. changed the /usr/lib/jvm/default-java symlink to point to java-7-openjdk-amd64 ,
  3. double checked all the environment variables (my JAVA_HOME and JDK_HOME both point to /usr/lib/jvm/default-java),
  4. reconfigured my project's SDK appropriately (and for all the modules in the project),

and voila - problem solved!

like image 66
Aleksander Adamowski Avatar answered Sep 27 '22 16:09

Aleksander Adamowski