maven打包以及配置分离

maven打包以及配置分离_第1张图片
按住shift 点击鼠标右键,点击“在此处打开命令窗口”,在窗口中输入“mvn package”,如下图
maven打包以及配置分离_第2张图片
我的没有配环境,要在maven安装目录下找到bin目录,并记录该路径,然后复制到命令窗口中,如下图
maven打包以及配置分离_第3张图片
回车,等待结果,结果如下(不要关闭命令窗口)
maven打包以及配置分离_第4张图片
在项目target目录下可以看到生成的jar
这里写图片描述
在命令窗口中输入:clean -P test source:jar install -Dmaven.test.skip
执行配置分离,想完成这一步需要在代码中进行配置,否则无法成功。
目录结构如下:
maven打包以及配置分离_第5张图片
pom.xml中添加:


  <build>
        
        <finalName>ticketapply-schedulefinalName>
         <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <filtering>truefiltering>
                <excludes>
                    <exclude>assemble/*.xmlexclude>
                    <exclude>conf/**/*.*exclude>
                excludes>
            resource>
        resources>
        
        <plugins>
            <plugin>
                <artifactId>maven-assembly-pluginartifactId>
                <configuration>
                    <appendAssemblyId>trueappendAssemblyId>
                    <descriptors>
                        <descriptor>src/main/resources/assemble/package.xmldescriptor>
                    descriptors>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid>
                        <phase>packagephase>
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
  build>

  
  <profiles>
    <profile>
        
        <id>testid>
        <build>
        
        <plugins>
            <plugin>
                <artifactId>maven-assembly-pluginartifactId>
                <configuration>
                    <appendAssemblyId>trueappendAssemblyId>
                    <descriptors>
                        
                        <descriptor>src/main/resources/assemble/dubboPackage.xmldescriptor>
                        <descriptor>src/main/resources/assemble/dubboConfigPackage.xmldescriptor>
                    descriptors>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid>
                        <phase>packagephase>
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
             plugin>
         plugins>
      build>
    profile>
  profiles>

dubboConfigPackage.xml

<assembly 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/xsd/assembly-1.0.0.xsd">
    <id>dubboConfigid>
    <formats>
        <format>zipformat>
    formats>
    <includeBaseDirectory>falseincludeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/confdirectory>
            <outputDirectory>dubboConfigoutputDirectory>
            <includes>
                <include>**/*.propertiesinclude>
            includes>
        fileSet>
    fileSets>
assembly>

dubboPackage.xml

<assembly 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/xsd/assembly-1.0.0.xsd">
    <id>packageid>
    <formats>
        <format>zipformat>
    formats>
    <includeBaseDirectory>falseincludeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/confdirectory>
            <outputDirectory>confoutputDirectory>
            <excludes>
                <exclude>**/*.propertiesexclude>
            excludes>
        fileSet>
    fileSets>
    <dependencySets>  
        <dependencySet> 
            <useProjectArtifact>trueuseProjectArtifact>  
            <outputDirectory>liboutputDirectory>
              
            <scope>runtimescope>  
        dependencySet>  
    dependencySets>  
assembly>

package.xml

<assembly 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/xsd/assembly-1.0.0.xsd">
    <id>packageid>
    <formats>
        <format>zipformat>
    formats>
    <includeBaseDirectory>falseincludeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/confdirectory>
            <outputDirectory>confoutputDirectory>
        fileSet>
    fileSets>

    <dependencySets>  
        <dependencySet> 
            <useProjectArtifact>trueuseProjectArtifact>  
            <outputDirectory>liboutputDirectory> 
            <scope>runtimescope>  
        dependencySet>  
    dependencySets>  
assembly>

命令窗口中输入命令并执行
这里写图片描述

这里写图片描述
target目录下会多出几个文件
这里写图片描述
dubboConfig是所有配置文件,package是spring文件+配置文件+lib,sources是源码

你可能感兴趣的:(java,maven)