How to run java program in command prompt,created by intellij
Three issues:
You have to specify the fully qualified class name (that means including the package name) to the
java
command. It looks like yourmyjava
class is in a packagecom.myexample.test
. So its fully qualified name iscom.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 thejava
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 insidesrc
, 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
It looks like the class is in a package com.myexample.test
. Try running
java com.myexample.test.myjava
from the project's bin
directory
From intellij, open your project structure, and click on Modules. You'll be able to see the output path. Usually, it's something like (if on mac):
~/../out/production/{context}.
Back to your example in windows. The path you gave is, C:\myjava\sampl1\src\com\myexample\test>, so you have your project in :
C:\myjava
directory where your context (or project name) is sampl1
.
That means that your output (*.class files) will be in
C:\myjava\sampl1\out\production\sampl1
Navigate into the folder and then run the command:
java com.myexample.test.myjava
I hope this can help somebody, a little late but, just I had this problem, ok my solution it next: 1. Run your code normally and copy the command line that the IntellijIDEA made, see the screenshot.
2.Copy and paste the command line that it uses to use with your params.