Packing under Maven, War packet, the Jar package, do not tell silly

To book hates few when goes, little to tell?

Friday, we should develop good projects will be posted on the test environment, you need to pack. Before packing, suddenly thought of a problem, in the end should be packaged into war package, or is it packaged into a jar package, before the package has not played. There was then a few times, the boss asked me to compile the project had sent him, was also forced to look ignorant, know what to do, but fortunately he told me, is compressed under the tomcat path, and now recall, but do not remember that is the war package or jar package?

When using maven built project, Choice is a jar package or war package, it was also not considered so much, but did not think any war bag and jar package, directly by default into the war package, and now you want to publish the project, or to take break it in the end what the package should be used, or how to publish a project it?

Jar Introduction

Jar package, the extension is .jar, java application archive is short, common libraries, resources, and other auxiliary files containing the java.

Mind the impression

Maven before use, what is required is to manually import the package holder, such as connecting frame needs mysql database package, put the carrier bag is introduced through the development of tools, or manually into the lib folder, these packages are jar package holder .

War Introduction

War package, the extension .war, is short for Web application archive, to see that this is the full name of a web application, a Web application includes a separate set of files, classes and resources, class file, there are jsp files.

Mind the impression

In previous projects, such as using SSH framework, development projects need to be deployed to run in Tomcat, before starting Tomcat, the first project released under Tomcat, after starting Tomcat, Tomcat will compile the entire project, compiled the java bytecode files are files whose .class, decompile software to use to open it, the file is still jsp jsp files.

the difference

war package just bytecode file also contains jsp page, and so on, war is a package for web applications, can be placed under the packed containers such as Tomcat, start Tomcat can run. jar package equivalent to a package good tool, by definition, there is only through the libraries, resources, auxiliary files.

Now I understand what they have to be packaged into a file, are developing their own service interface, no half jsp files, packing directly into the Jar package on it.

Jar package packed under maven
The first step, use the command maven clean

In eclipse, the selected item, right click and select Run as, run maven clean command, the results actually being given, the amount of this error seems to have seen


3816895-0e48e6068535fa10.png
figure 1

Select the item, right click and select properties, find maven, then remove the pom.xml input box, as shown below


3816895-f8c50ed2e1e9eddb.png
figure 2

Again maven clean look, the results BUILD SUCCESS.
The second step, using the maven install command

Then use maven install it, for a mistake, running on a JRE rather than a JDK?
It seems, it does not do it in English, which is the sense of the words, instead of using the jre jdk, then change it, to replace jre jdk, again, after the change, the results BUILD SUCCESS.

The third step is to find the target file in the root directory of the project folder, the resulting files are packaged in this folder, copy the jar package, placed in the designated folder, ready to publish it
3816895-a3bf6a5676930962.png
image 3
The fourth step, open the Cmd window, go to the next folder where the file shelf package, you can use the shortcut key ctrl + shift + right-click to open windows powershell here and run java -jar shelf package name, you can publish the project a.
3816895-b1d29587604a64b2.png
Figure 4

Found not publish jar, using a jar command, pack several times, I had overlooked that detail.

Complications

If you want to publish several projects, enter a command like this every time, but also very tired ah, is not it. Heard bat file that can be run directly, then try it with a bat file, how to write, it will not be hard, only to find later tried, So Easy.

First, create a text file, enter the command java -jar frame inside the package name
3816895-528a1ca27cfa7fca.png
Figure 5
The second step, change the file extension .bat file, and then save and close every startup, double-click the file to
3816895-695f112edeadde6e.png
Image 6

In this way, each time you need to restart the project, just one click on it, someday they're not, you can start other colleagues, but also save a lot of effort.


3816895-47253e72024f750d.jpg
Micro-channel sweep swept away, attention to life Cheng

Guess you like

Origin blog.csdn.net/weixin_33851429/article/details/90977332