简体   繁体   English

我如何在没有IDE的情况下编译和运行Intelij IDEA Java项目?

[英]How do I compile and run Intelij IDEA java project without IDE?

Recently I was trying to run 2048 bot . 最近我正在尝试运行2048 bot I'm not a java programmer and installing IDE just for running one program would be overkill. 我不是java程序员,而仅为了运行一个程序而安装IDE会显得过头了。 So I tried compiling and running it from command line, but that was not a simple task for me, mainly because of the dependencies . 因此,我尝试从命令行编译并运行它,但这对我来说并不是一个简单的任务,主要是因为依赖关系 Then I was told, that maven might come in handy. 然后我被告知, maven可能会派上用场。 So I wonder if one can easily compile and run a program using maven or whatever tool they have without installing IDE ? 所以我想知道是否可以使用maven或他们拥有的任何工具轻松地编译和运行程序而无需安装IDE

The pom.xml file will have everything in it you need to compile it. pom.xml文件将包含您进行编译所需的所有内容。 In this particular case, it is only declaring a single dependency, the selenium-firefox-driver . 在这种特殊情况下,它仅声明了一个依赖项selenium-firefox-driver With maven, all POM (Project Object Model) files inherit defaults from a "master" parent POM file. 使用Maven,所有POM(项目对象模型)文件都将从“主”父POM文件继承默认值。 Maven uses a "convention over configuration" philosophy. Maven使用“约定之上的配置”理念。 Anything not explicitly configured, defaults to standard configurations from the parent pom that is part of maven. 任何未明确配置的内容,默认为来自maven的父pom的标准配置。 That is why you can build a project from such a seemingly simple POM file. 这就是为什么您可以从看似简单的POM文件构建项目的原因。

You will not be able to run the build from the IntelliJ IDEA module ( .iml ) file. 您将无法从IntelliJ IDEA模块( .iml )文件运行构建。 In fact, IntelliJ IDEA generates that file from the POM. 实际上,IntelliJ IDEA是从POM生成该文件的。

First, make sure you have a Java JDK installed . 首先,确保已安装Java JDK Java 8 is the latest current. Java 8是最新的。 But a Java 7 JDK would be fine. 但是Java 7 JDK可以。 After that, the Running Maven link @jeroen_de_schutter provided has all the information you need. 之后,提供的Running Maven链接@jeroen_de_schutter包含了您需要的所有信息。 Click on the top link in that document to Download and Install Maven . 单击该文档中的顶部链接以下载并安装Maven Once that is done, from a command line, navigate into the directory that contains the project (ie the directory with the pom.xml file in it) and issue the command: mvn compile to compile your code, mvn test to compile and test, or mvn package to compile, test and package the code. 完成此操作后,从命令行导航到包含项目的目录(即其中包含pom.xml文件的目录)并发出命令: mvn compile编译代码, mvn test进行编译和测试,或mvn package来编译,测试和打包代码。 You can add clean to that any of those commands so maven will do a clean build. 您可以在所有这些命令中添加clean ,以便maven可以进行clean构建。 For example: mvn clean package . 例如: mvn clean package See the second Quick Start and third Use Maven links in the Running Maven document for more details and information. 有关更多详细信息,请参阅“ 运行Maven”文档中的第二个“ 快速入门”和第三个“ 使用Maven”链接。

Please note that the first time you run a build (any maven build) it will take quite a bit longer than normal. 请注意,第一次运行构建(任何Maven构建)将花费比正常时间更长的时间。 This is because maven has to download (and cache) a ton of plug-ins and dependencies. 这是因为maven必须下载(和缓存)大量的插件和依赖项。 Once that is done, the builds go much much quicker. 一旦完成,构建就会快得多。 However, the first time you build a new project, the first build make take a little longer as it downloads and caches the dependencies and plug-ins needed by that project that have not already been retrieved. 但是,第一次构建新项目时,第一次构建会花费一些时间,因为它会下载并缓存该项目所需的尚未检索到的依赖项和插件。

Yes you can, make sure you have a Java Development Kit and Maven installed. 是的,可以,请确保已安装Java开发工具包和Maven。 Then by following the Maven user guides you should be able to build it and run. 然后,通过遵循Maven用户指南,您应该能够构建它并运行。 But it might not be straightforward if you have never used maven, so I would recommend to ask the assitance of an experienced java developer, if you happen to know one. 但是,如果您从未使用过Maven,这可能并不容易,因此,如果您碰巧知道一个,那么我建议您咨询经验丰富的Java开发人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM