1

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!

illwalkwithyou
  • 349
  • 1
  • 6
  • 21
  • What is the command You are using, and in what directory do You launch it?. Why don't You just export jar file and run it? – maslan Jan 25 '15 at 20:59
  • I am using the command: "java main.FileMonitor" to try run my program. I don't mind which directory I launch it in. – illwalkwithyou Jan 25 '15 at 21:40

1 Answers1

1

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.
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    Thanks! Copied the command that IntellIj uses to run the program. Removed all the unnecessary stuff and it ran great. Not got any experience with Maven but may try that approach in the next few days. – illwalkwithyou Jan 25 '15 at 22:04