illwalkwithyou
illwalkwithyou

Reputation: 359

Running a Java program created in IntelliJ on Windows Command Line

I have seen many people ask this question but none of the answers have solved my problem.

I have written a Java project in Intellij which runs fine in Intellij. I need it to run on the command line however.

Intellij automatically builds the .class files in the following directories which is outlined as follows:

C:\git\myProject\out\production\myProject\main
C:\git\myProject\out\production\myProject\openNlpTools
C:\git\myProject\out\production\myProject\sentimentAnalysisTools

I have three sub directories here. The file with the main method is in the \main folder.

To run the program I thought I used the following:

java main.FileMonitor

When I run this however I get the following error:

Error: Could not find or load main class main.FileMonitor

Does anyone have any tips as to why this isn't running? Intellij runs the program fine, is there anyway I can see the command IntelliJ uses to run the program?

Thanks!

Upvotes: 1

Views: 5125

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533880

If you can't file a class it usually means you didn't include it in your class path. Some ways to run in the command line

Copy from IntelliJ

  • Run the program in InetlliJ.
  • Copy the first line as this will contain full command line
  • Edit the command line to remove bits you don't need.

Using Maven/Gradle

  • Set the Main-Class in the assembly plugin
  • build the program with assembly:single
  • this will create a Jar you can run on the command line.

Upvotes: 1

Related Questions