IntelliJ refuses to run a simple Java code
42 minutes ago, ApexArticO5 said:Hmm, for me it doesn't create the directory of "scr/main/java". If I launch it without sample code It just has "src" without anything inside it and if I launch it with sample code its puts a main.java file directly inside of "src".
Maybe I need to get an older version?
I'm on the latest version of IntelliJ (2024.2.1). I'm on Linux and using Java 21 (LTS), rather than Java 22, and also using the Ultimate Edition. But none of that should really make much of a difference here. My suspicion is that it has to do with the project's location.
Looks like the difference in file structure is down to us selecting different build systems when creating a new project. You selected IntelliJ as the build system, while I selected Gradle (which is what we use at work). If I create a new Java project with IntelliJ as the build system, I get the same file structure you do. However, I'm still able to run the code afterwards.
Top right I can see that yours says "Main" next to the run button, while mine says "Current File", so that's one difference. My primary suspicion would be that it has issues with the non-latin characters in your path. Maybe try creating the project in a different directory.
If I run the code, this is the command line that I get:
/usr/lib/jvm/default-runtime/bin/java \ -javaagent:/opt/intellij-idea-ultimate-edition/lib/idea_rt.jar=42941:/opt/intellij-idea-ultimate-edition/bin \ -Dfile.encoding=UTF-8 \ -classpath /home/<username>/git/untitled/out/production/untitled \ Main
If I copy this line and run it in the terminal, I get the expected "Hello world!" output.
Take a closer look at your output, specifically the end of this line here ("C:\Program Files\Java\…\java.exe"). That's how it tries to run the code.
I assume if you copy and paste this line and run it in the Windows terminal, you'll get the same error. Meaning something in that line is broken. If you can figure out what it is (path?) that should help point towards how to fix it.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now