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

后端 未结 6 579
情深已故
情深已故 2021-02-06 00:10

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 ID

相关标签:
6条回答
  • 2021-02-06 00:47

    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 讨论(0)
  • 2021-02-06 00:51

    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. :)

    0 讨论(0)
  • 2021-02-06 00:51

    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 讨论(0)
  • 2021-02-06 00:54

    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).

    0 讨论(0)
  • 2021-02-06 01:01

    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 讨论(0)
  • 2021-02-06 01:09

    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!

    0 讨论(0)
提交回复
热议问题