0

I know how to run my Java program from the command line. My path to Main.java is:

my_dir/turtlesolution

turtlesolution has the following:

Main.java
Turtle.java
Turtles.java

I opened turtlesolution as the project, using IntelliJ. I then opened (by double clicking) Main.java. I want to run this. I have to edit configurations before I run it, it seems.

So I clicked edit configurations. I clicked JAR application because this looks like the option. This is what comes up:

enter image description here

Working directory, I set it to point to turtlesolution. What is Path to JAR? I tried to set it to turtlesolution but it remains blank. What does Warning, jar file doesn't exist mean?

I can run it from the command line by just doing

cd turtlesolution
javac Main.java Turtle.java Turtles.java
cd ../
java turtlesolution/Main

Aapprently it's very easy to figure out. I'm in my final year of learning CS in university and apparently it's simple, but I can't figure out how to do it, and it's too simple to teach ...

  • See https://www.jetbrains.com/help/idea/creating-running-and-packaging-your-first-java-application.html and https://www.jetbrains.com/help/idea/running-applications.html. – CrazyCoder Mar 03 '20 at 22:28
  • @CrazyCoder I've seen both. Neither answer the question. – user2272600 Mar 03 '20 at 22:35
  • @CrazyCoder The first seemed to explain how to run it if I start from scratch, but I an opening an existing `turtlesolution` project. The second just says "select desired configuration". I'm asking how exactly I should configure it to be able to make it run similar to how I do `javac` then `java turtlesolution/Main` from command line. Thanks! – user2272600 Mar 03 '20 at 22:37
  • Where does it say to use JAR Application? You just use the normal Application, also make sure you have the sources in the source root, see https://stackoverflow.com/a/43319356/104891. – CrazyCoder Mar 03 '20 at 22:37
  • Start from scratch as described in the help, then just copy your `.java` files to the **src** directory, then click on the green arrow on the left of the main method/class to run it. – CrazyCoder Mar 03 '20 at 22:39
  • Or right click on the directory with `.java` files, choose `Mark Directory as` | `Source Root`, then click on the green arrow on the left of the main class/method in the editor to run it. – CrazyCoder Mar 03 '20 at 23:04

1 Answers1

1

If you don't have any run configuration in the project, Run button is also disabled. If you right click in a file with main method, run configuration is created automatically and main class value if prefilled. This worked for me for more vist https://intellij-support.jetbrains.com/hc/en-us/community/posts/206811415-Problem-with-Edit-Configurations-

Ebsa Teklu
  • 29
  • 2