How to run java program in command prompt,created by intellij

intellij-idea, java

Solution

Three issues:

You have to specify the fully qualified class name (that means including the package name) to the `java` command. It looks like your `myjava` class is in a package `com.myexample.test`. So its fully qualified name is `com.myexample.test.myjava`.

When you run the `java` command you have to be in the directory that is at the base of the package hierarchy (or put that directory on the classpath).

You're using the `src` directory, which contains `.java` source files, but the `java` command expects compiled `.class` files, so you need to use the project's output directory. Its location in your project will depend on your IDE and configuration but it will contain same-named structure as inside `src`, except with `.class` files instead of `.java` files.

In your case, navigate to:

C:\myjava\sampl1\out\production\

Then run:

java com.myexample.test.myjava

Problem

How do I run my Java program in command prompt, my project was created in Intellij, and I am having difficulties running it in the command prompt...without using the Intellij in creating project,I can run the java program in command prompt. I do this like this. ``` java myjava ->this would work. ``` but the project created by Intellij,this is the path. ``` C:\myjava\sampl1\src\com\myexample\test> ``` when I issue this command ``` java myjava -> Error: Could not find or load main class myjava ``` but I am inside in that directory. Thank you in advance.

Original source