Use IntelliJ IDEA to create an EXECUTABLE JAR With Dependencies Using Maven

Begin Secure
Begin Secure
39 هزار بار بازدید - 2 سال پیش - In this video, we will
In this video, we will use IntelliJ IDEA to create an executable jar file using Maven.

Keep watching until the end of the video to see a second way to create an executable jar that will take up less space in your deployments, so you can optimize your images.

We're using IntelliJ IDEA Community Edition, which is free. Using IntelliJ is a great way to make programming more productive and enjoyable.

▬▬▬▬▬▬ T I M E S T A M P S ⏰  ▬▬▬▬▬▬

00:00 Create the project
02:30 Review Maven setup
03:10 Add first dependency
03:40 Security Alert
05:45 Add second dependency
07:41 Execute the jar file
09:19 Modify the code to include the dependency
11:15 Package the dependency
12:19 Build the artifact
14:02 Add Maven plugin to project
15:10 Build the code with the new plugin

When IntelliJ is working, I have sped up the boring parts, so we can focus on what's interesting
IntelliJ creates our project and provides us with a very basic pom.xml.

We see the group and artifact id we provided earlier in our pom file, along with the default version of the 1.0 snapshot.

Any recent version of java will be fine, we’ll be using version 11.

In the project tool window, we’ll right click on source, main, java and select new java class
We’ll supply the name of the package and the class file name at one time
Let’s call it com dot beginsecure dot app and press return
Intellij creates our class
Lets use the live template psvm to generate our main method
And we’ll use the live template sout to generate our printline statement
In our message, let’s put in the string hello world because of course
And let’s run that code just to show that everything is working correctly
We see the code runs, prints our message and exits with a return code of 0
Great, everything is working as expected,
Let’s take a moment and look at the maven tool window
On top we see a list of the lifecycle phases, clean, validate, compile and so forth.
A phase is a step in the build lifecycle which is an ordered sequence of steps
When a phase, like package, is specified, every phase in the sequence up to and including the one specified is run
Below is a list of the plugins that are available to use by default from IntelliJ IDEA
When we invoke plugins, we specify a goal to perform.
For example, the plugin we might invoke is compiler and the goal is compile
Back in the Project tool window, we see the external libraries this project is dependent on
For now, JDK 11 is the only thing necessary to build this project
Let’s change that and explore how we can add a dependency to our project

You can find the code here: https://github.com/BeginSecure/Intell...
2 سال پیش در تاریخ 1401/06/21 منتشر شده است.
39,081 بـار بازدید شده
... بیشتر