Windows命令行上运行在IntelliJ中创建的Java程序

Windows命令行上运行在IntelliJ中创建的Java程序

本文介绍了在Windows命令行上运行在IntelliJ中创建的Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多人问这个问题,但是没有一个答案能解决我的问题.

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

我已经用Intellij编写了一个Java项目,该项目在Intellij中运行良好.我需要它在命令行上运行.

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

Intellij自动在以下目录中构建.class文件,其概述如下:

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

我在这里有三个子目录.带有main方法的文件位于\ main文件夹中.

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

有人对为什么它没有运行有任何提示吗?Intellij可以很好地运行程序,反正我还能看到IntelliJ用于运行程序的命令吗?

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?

谢谢!

推荐答案

如果您无法提交课程,则通常意味着您未将其包括在课程路径中.在命令行中运行的一些方法

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

从IntelliJ复制

Copy from IntelliJ

  • 在InetlliJ中运行程序.
  • 复制第一行,因为它将包含完整的命令行
  • 编辑命令行以删除不需要的位.

使用Maven/Gradle

Using Maven/Gradle

  • 在程序集插件中设置 Main-Class
  • 使用 assembly:single
  • 构建程序
  • 这将创建一个可以在命令行上运行的Jar.

这篇关于在Windows命令行上运行在IntelliJ中创建的Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:49