1
votes

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!

1
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
I am using the command: "java main.FileMonitor" to try run my program. I don't mind which directory I launch it in. - illwalkwithyou

1 Answers

1
votes

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.