(maven gradle )+idea +(jar war)包

maven packaged into a jar
select maven project with the idea of quickly generating projects and packaged into a jar, as well as their own group Artifact definition, then click Next to have been completed.
Here Insert Picture Description

Easily build a controller, start the project, with the corresponding address of the default port of 8080 as well as in the figure below, you can have access to

Here Insert Picture Description

M click on the right button, find the package to perform, or to perform mvn package in the following terminal

Here Insert Picture Description

The following diagram, the package proved successful

Here Insert Picture Description
According to the chart to find the path after compiling, you can perform right after the selected
Here Insert Picture Description
Here Insert Picture Description

Similarly, modifications packaged in WAR pom.xml way, perform the same steps described above, the success of the packer below

Here Insert Picture Description
Directly run java -jar demo-0.0.1-SNAPSHOT.war
below, starting with the results of the jar is the same way
Here Insert Picture Description

Here are some ways gradle packaged
for convenience with commands to turn the items maven gradle projects
performed in the root directory: gradle init --type pom
Here Insert Picture Description

The following figure generated gradle related things, manually delete the relevant maven
Here Insert Picture Description
restart the idea into the project, there will be a prompt to let you build, the background will be shown below after clicking bulid
Here Insert Picture Description

During the normal start of the project, you can still start a successful return to the current project, but also the normal access

Here Insert Picture Description

And then re-execute the root of the terminal project
gradle Build
Here Insert Picture Description
posted below gradle jar packed configuration and war, are generated by default idea
jar:

buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

war:

buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

Java -jar is also performed corresponding to jar or war

Published 24 original articles · won praise 6 · views 20000 +

Guess you like

Origin blog.csdn.net/li_yan_sring/article/details/84591138