Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Java Gradle project and building the .jar file in IntelliJ IDEA - How to?

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, maybe I should create another project, then copy/paste the Main.class and Gradle's dependencies from the old project onto the new project.

If this is my best option, how do I correctly create the project this time?

like image 535
Defozo Avatar asked May 08 '16 12:05

Defozo


1 Answers

  1. Create new Gradle (not Java) project. Be sure to select Java option in the dialog. Click Next. enter image description here

  1. fill GroupId, ArtifactId and version enter image description here

  1. Choose your gradle distribution. You can safely use the reccommended option. enter image description here

  1. Choose project name and location enter image description here

  1. Click finish

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

  1. You build your sources using Gradle tab → tasks → build (double click) enter image description here

  1. You can see the result of the build in the Run tab enter image description here

  1. In case of error, you can see details by clicking the following button: enter image description here
like image 69
Vojtech Ruzicka Avatar answered Sep 21 '22 05:09

Vojtech Ruzicka