Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 226
ashTon Avatar asked Nov 24 '14 15:11

ashTon


People also ask

How run IntelliJ program from command line?

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.


1 Answers

Three issues:

  1. 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.

  2. 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).

  3. 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 
like image 93
Boann Avatar answered Oct 17 '22 06:10

Boann