intellij gradle java,在IntelliJ IDEA中创建Java Gradle项目并构建.jar文件-如何?

Is there a tutorial explaining how to properly create a Java Gradle project and build the .jar file?

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

or

Error: Could not find or load main class Main

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?

解决方案

Create new Gradle (not Java) project. Be sure to select Java option in the dialog. Click Next.

Q4i3s.png

fill GroupId, ArtifactId and version

VKfWC.png

Choose your gradle distribution. You can safely use the reccommended option.

13WmW.png

Choose project name and location

9U8BZ.png

Click finish

You put your java classes to src/main/java folder. When using third party libraries, make sure you declare them as Gradle dependencies.

wR1Cb.png

You build your sources using Gradle tab → tasks → build (double click)

EjUYv.png

You can see the result of the build in the Run tab

gl0YP.png

In case of error, you can see details by clicking the following button:

wQQPy.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值