11
votes

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

6
I also have the same problem. Intelij Idea community edition on ubuntu 11.10. Compiles ok with javac, but gives an error in IDE(No such file) - Marcus Maxwell
Try to remove all JSDK and add them again in intelij idea, both the jdk6 and jdk7 :) - Marcus Maxwell

6 Answers

7
votes

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!

5
votes

Solved it. Remove all jdk/jre you have, install openjdk7.

Add this line to .bashrc

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/
export PATH=$PATH:$JAVA_HOME/bin

Run Idea. Profit. :)

2
votes

I experienced the same problem. What I found is that the underlying system-wide Java version doesn't matter, so there is no need to set JAVA_HOME or update_alternatives. All I had to do was change some settings in IDEA:

  • Add a Java SDK, either OpenJDK 7, or Oracle JDK 6 or 7 (File -> Project structure -> SDKs)
  • Select it as Project SDK (File -> Project structure -> Project)
0
votes

Check that Make checkbox is enabled, otherwise IDEA will not compile your project, also verify that class file is available in the output directory and you are running with the classpath of the correct module.

If the problem remains, send a sample project to support.

0
votes

I've run into the same problem - I moved my projects (and Idea settings) from a laptop with Ubuntu 10.04 and sun-jdk-6 to a PC with Ubunty 11.10 and openjdk-6. Upon project rebuild I got MyClass.class (No Such file or directory) errors for ALL classes.

Thanks to Jaroslav, his (almost) solution did helped - I can't explain why, perhaps it would work with sun-jdk-6 too... So, I installed openjdk-7, without removing openjdk-6, and set 7th as a project's JDK in Idea. (I did not change anything in environment variables.) With jdk7 it compiled.

PS I should've written it as a comment to Jaroslav's post, not a separate answer, but I don't yet have enough reputation to do this...

0
votes

Try to run IDEA using

sh -c "export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386 && ./idea.sh"

When it starts press Ctrl+Alt+Shift+S to open Project Settings dialog. In the left panel choose Project and verify that Project SDK is configured correctly (at least it is not red).