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.
Open IntelliJ IDEA, go to Tools->Create Command-Line Launcher... and optionally adjust the location and name of the script that will start IntelliJ IDEA. Voilà! Now from your command line, you can type: idea . to open the project in the current directory.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With