Exported jar package cannot run?
Can’t find main class for exported jar package?
Maybe I don’t have a deep understanding of exporting jar package. Anyway, I still don’t know how to use the interface and functions of exporting jar package from idea. But I finally found out the right way.
Step 1: add a build
The first thing to introduce isArtifactThis concept can be understood as a kind of construction. For example, the artifact built by Android studio is an APK file. Java programs, of course, can build jar packages.
In a Java or kotlin project, on the toolbar at the top of the idea, locate the project structure icon.
Or in,File -> Project Structures...
It can also be found.
Click to open the project structure window.
As shown in the figure below, you can select artifacts on the left side of the project structure window, click the plus sign on the right side, and select Jar – > empty
On the right side of the window, an editable interface appears. As shown in the following figure: the red box above is to fill in the name of jar package, the red box at the bottom left indicates what is contained in the jar package, and the red box at the bottom right indicates what can be put in.
Step 2: add a manifest
When nothing is added to jar, click xxx.jar , the action button to add a Manifest is displayed at the bottom.
After adding, specify main class. As shown in the figure below:
Step 3: add jar package content
The next step isMost criticalOperation of.
For the source code in the project, it is generally displayed as’ XXXX ‘compile output. The operations for them are: right click and selectPut into Output Root。
For the dependent libraries in the project, right-click and selectExtract Into Output Root。
Finally, we will get the following results.
Step 4: build
After the above steps, an artifact is configured. We can do it.
In the menu bar, build – > build artifacts
Click build to build.
The generated items should be in the output or out or build directories.
Do it nowjava -jar yourJar.jar
Try it!