在IntelliJ IDEA中创建Java Gradle项目并构建.jar文件-如何? [英] Creating a Java Gradle project and building the .jar file in IntelliJ IDEA - How to?
问题描述
是否有教程说明如何正确创建Java Gradle项目并构建.jar文件?
Is there a tutorial explaining how to properly create a Java Gradle project and build the .jar file?
当我创建一个Java项目并添加Gradle时:File->新->模块->摇篮-> ...我收到有关Java EE websocket不可用的错误(我使用的是Ultimate Edition).但是,我可以通过选择File->来成功创建项目.新->项目->摇篮->这给了我一个可以调试的带有Gradle的Java项目.但是,当我尝试创建工件(.jar文件)时,出现错误.我认为这些错误是由于我在项目结构设置中犯的错误引起的.
When I create a Java project and add Gradle: File -> New -> Module -> Gradle -> ... I receive errors about Java EE websocket's not available (I'm using Ultimate Edition). However, I can successfully create a project by selecting File -> New -> Project-> Gradle -> which gives me a Java project with Gradle that I can debug. However, when I try to create an artifact (.jar file) I receive errors. I assume the errors stem from mistakes I made in the project structure settings.
Buildfile: build.xml does not exist!
Build failed
或
Error: Could not find or load main class Main
此时我的项目太乱了,我认为最好的选择是创建另一个项目,并将Main.class和Gradle的依赖项从旧项目复制/粘贴到该项目上.
My project is such a mess at this point that I think the best option is to create another project and copy/paste the Main.class and Gradle's dependencies from the old project onto it.
但是,这次我如何正确创建项目?
But, how do I create the project correctly this time?
推荐答案
- 创建一个新的Gradle(不是Java)项目.确保在对话框中选择Java选项.点击下一步.
- Create new Gradle (not Java) project. Be sure to select Java option in the dialog. Click Next.
- 填写GroupId,ArtifactId和版本
- fill GroupId, ArtifactId and version
- 选择您的gradle分配.您可以安全地使用推荐的选项.
- Choose your gradle distribution. You can safely use the reccommended option.
- 选择项目名称和位置
- Choose project name and location
- 点击完成
- 您将Java类放入src/main/java文件夹.使用第三方库时,请确保将它们声明为Gradle依赖项.
- You put your java classes to src/main/java folder. When using third party libraries, make sure you declare them as Gradle dependencies.
- 您可以使用Gradle选项卡→任务→构建源代码(双击)
- You build your sources using Gradle tab → tasks → build (double click)
- 您可以在运行"选项卡中查看构建结果
- You can see the result of the build in the Run tab
- 如果发生错误,您可以通过单击以下按钮查看详细信息:
- In case of error, you can see details by clicking the following button:
这篇关于在IntelliJ IDEA中创建Java Gradle项目并构建.jar文件-如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!