亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

自定義Maven Archetype之 maven-archetype-archetype

發布時間:2020-07-03 15:39:47 來源:網絡 閱讀:2013 作者:mybabe0312 欄目:軟件技術

Maven自身提供了許多Archetype來方便用戶創建Project,但是每個團隊都可能會有一些常用的文件或配置,為了避免在創建project時重復的拷貝和修改,我們通過自定義Archetype來規范顯得還蠻有必要,下面簡單介紹下使用maven-archetype-archetype來構建自己的Archetype的過程。

1,創建自己的Archetype項目

模板

mvn archetype:generate   \
  -DarchetypeGroupId=<archetype-groupId>  \
  -DarchetypeArtifactId=<archetype-artifactId> \
  -DarchetypeVersion=<archetype-version>   \
  -DgroupId=<my.groupid> \
  -DartifactId=<my-artifactId>

例如:

mvn archetype:generate \
  -DgroupId=com.ultrapower.maven.archetypes \
  -DartifactId=springboot-maven-archetype  \
  -DarchetypeArtifactId=maven-archetype-archetype   \
  -DinteractiveMode=false \
  -X

自定義Maven Archetype之 maven-archetype-archetype

1) springboot-maven-archetype下的pom.xml和一般的maven項目一樣用于定義archetype項目的坐標等信息
2) springboot-maven-archetype/src/main/resources/archetype-resources下的所有內容定義了待生成項目的所有文件(原型文件)
3) springboot-maven-archetype/ src/main/resources/META-INF/maven/archetype.xml中定義骨架的描述符(元數據),這個文件列出了包含在archetype中的所有文件并將這些文件分類。

注:springboot-maven-archetype/pom.xml如下

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ultrapower.maven.archetypes</groupId>
    <artifactId>springboot-maven-archetype</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Archetype - springboot-maven-archetype</name>
    <url>http://maven.apache.org</url>
</project>

2,修改archetype-resources下的pom.xml,添加需要的配置

如:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>${groupId}</groupId>
    <artifactId>${artifactId}</artifactId>
    <version>${version}</version>
    <packaging>jar</packaging>
    <name>${artifactId}</name>
    <url>http://www.myorganization.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

3,添加需要的文件

例如:
自定義Maven Archetype之 maven-archetype-archetype

如Application.java

package ${package};

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
        JmsAutoConfiguration.class })
@ServletComponentScan
@ComponentScan(basePackages = { "${package}" })
public class Application {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(Application.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.run(args);
    }
}

如CorsConfig.java

package ${package}.config.beanconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CorsConfig {
    private CorsConfiguration buildConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        // 1 設置訪問源地址
        corsConfiguration.addAllowedOrigin("*");
        // 2 設置訪問源請求頭
        corsConfiguration.addAllowedHeader("*");
        // 3 設置訪問源請求方法
        corsConfiguration.addAllowedMethod("*");
        return corsConfiguration;
    }

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        // 4 對接口配置跨域設置
        source.registerCorsConfiguration("/**", buildConfig());
        return new CorsFilter(source);
    }
}

4,修改archetype.xml文件

如:

<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">

    <id>springboot-maven-archetype</id>
    <sources>
        <source encoding="UTF-8">src/main/java/Application.java</source>
        <source encoding="UTF-8">src/main/java/config/beanconfig/MvcConfig.java</source>
        <source encoding="UTF-8">src/main/java/config/beanconfig/CorsConfig.java</source>
        <source encoding="UTF-8">src/main/java/config/beanconfig/RestTemplateConfig.java</source>
        <source encoding="UTF-8">src/main/java/config/beanconfig/Swagger2Config.java</source>
        <source encoding="UTF-8">src/main/java/config/condition/Swagger2Condition.java</source>
    </sources>
    <resources>
        <resource encoding="UTF-8">src/main/resources/application.yml</resource>
        <resource encoding="UTF-8">src/main/resources/application-dev.yml</resource>
        <resource encoding="UTF-8">src/main/resources/application-prod.yml</resource>
        <resource encoding="UTF-8">boot/control.sh</resource>
        <resource encoding="UTF-8">boot/control.bat</resource>
    </resources>
    <testSources>
        <source>src/test/java/AppTest.java</source>
    </testSources>
</archetype>

上面是將每個文件都列出來了,還可以使用通配符的方式來簡化配置,例如:

<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">

    <id>springboot-maven-archetype</id>
    <sources>
        <source encoding="UTF-8">src/main/java/**/*.*</source>
    </sources>
    <resources>
        <resource encoding="UTF-8">**/*.*</resource>
    </resources>
    <testSources>
        <source>src/test/java/AppTest.java</source>
    </testSources>
</archetype>

5,安裝archetype

mvn install

6,使用自定義的archetype創建項目

mvn archetype:generate  -DarchetypeGroupId=com.ultrapower.maven.archetypes  -DarchetypeArtifactId=springboot-maven-archetype  -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.ultrapower.ioss -DartifactId=springboot-archetype-test -X

注意: 我們可以將archetype.xml換成“archetype-metadata.xml”,以下的內容可以達到同樣的效果,但還是推薦archetype.xml

archetype-metadata.xml:
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="beast-archetype"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
            http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
            http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd">

    <requiredProperties>
        <requiredProperty key="package" />
    </requiredProperties>

    <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.java</include>
            </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </fileSet>
        <fileSet filtered="true" encoding="UTF-8">
            <directory>boot</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </fileSet>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
            <directory>src/test/java</directory>
            <includes>
                <include>**/*.java</include>
            </includes>
        </fileSet>
        <fileSet encoding="UTF-8">
            <directory>src/test/resources</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </fileSet>
    </fileSets>
</archetype-descriptor>
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

琼结县| 大埔区| 汤原县| 镇康县| 绥滨县| 抚顺市| 榆林市| 玉林市| 保康县| 泰兴市| 武功县| 连城县| 府谷县| 罗源县| 始兴县| 苏尼特左旗| 望谟县| 兰坪| 江山市| 萨嘎县| 庄河市| 仙居县| 无棣县| 九江县| 孝昌县| 明水县| 吉林省| 桃园市| 八宿县| 定南县| 保德县| 白朗县| 云龙县| 聊城市| 澄城县| 长垣县| 盐池县| 许昌市| 玛沁县| 海宁市| 攀枝花市|