在maven中,添加一个文件夹作为源文件夹,但不要将其包含在源jar中

时间:2014-01-31 08:56:52

标签: java maven maven-plugin maven-assembly-plugin

我有一个用例,我需要使用maven-buildHelper插件将文件夹target / schemas包含为源文件夹。我正在为这个项目制造一场战争。创建源jar时,目标/模式的内容也存在于其中。我不想将目标/模式的内容添加到我的源jar中。如何实现?

<?xml version="1.0" encoding="UTF-8"?>
<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>
   <parent>
      <groupId>***************</groupId>
      <artifactId>core</artifactId>
      <version>1.0.0</version>
   </parent>

   <artifactId>identity</artifactId>
   <packaging>war</packaging>

   <dependencies>
       ...............
   </dependencies>

  <build>
     <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
           <execution>
              <id>attach-sources</id>
              <phase>verify</phase>
              <goals>
                 <goal>jar</goal>
              </goals>
           </execution>
        </executions>
     </plugin>

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
           <failOnMissingWebXml>false</failOnMissingWebXml>
           <warName>identity</warName>
        </configuration>
     </plugin>

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
           <execution>
              <id>unpack</id>
              <phase>prepare-package</phase>
              <goals>
                 <goal>unpack</goal>
              </goals>
              <configuration>
                 <artifactItems>
                    <artifactItem>
                       <groupId>***************</groupId>
                       <artifactId>authentication-service</artifactId>
                       <version>${project.version}</version>
                       <classifier>sources</classifier>
                       <type>jar</type>
                       <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                       <includes>**/*.java,**/*.xml</includes>
                    </artifactItem>
                    <artifactItem>
                       <groupId>***************</groupId>
                       <artifactId>authorization-service</artifactId>
                       <version>${project.version}</version>
                       <classifier>sources</classifier>
                       <type>jar</type>
                       <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                       <includes>**/*.java,**/*.xml</includes>
                    </artifactItem>
                 </artifactItems>
              </configuration>
           </execution>
        </executions>
     </plugin>
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${maven.plugin.buildHelper}</version>
        <executions>
           <execution>
              <id>add-source</id>
              <phase>generate-sources</phase>
              <goals>
                 <goal>add-source</goal>
              </goals>
              <configuration>
                 <sources>
                    <source>${project.build.directory}/schemas</source>
                 </sources>
              </configuration>
           </execution>
        </executions>
     </plugin>
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>${maven.plugin.jaxb2}</version>
        <executions>
           <execution>
              <id>schemagen-combined</id>
              <goals>
                 <goal>schemagen</goal>
              </goals>
              <phase>prepare-package</phase>
              <configuration>
                 <includes>
                    <include>***************/core/identity/domain/*.java</include>
                    <include>***************/authentication/domain/*.java</include>
                    <include>***************/authorization/domain/*.java</include>
                 </includes>
                 <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                 <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
              </configuration>
           </execution>

        </executions>
     </plugin
  </plugins>

我有一个Web项目标识,它取决于两个jar身份验证和授权。在项目标识中,我使用jaxb2-maven-plugin为身份验证,授权和身份源生成xsd。作为插件jaxb2-maven-plugin,仅适用于maven源路径中存在的源,我在文件夹目标/架构中下载用于身份验证和授权的源,将此文件夹目标/架构添加为maven源文件夹,然后运行jaxb2 -maven-plugin生成xsd。现在,当我为身份构建源jar时,它还包括我不想要的身份验证和授权来源。

1 个答案:

答案 0 :(得分:1)

Maven Source plugin可以选择从已创建的源JAR中排除选定的文件。

  

exclude

     

要排除的文件列表。指定为相对于其内容被打包到JAR的输入目录的文件集模式。