有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我有一个用例,需要使用maven buildHelper插件将文件夹目标/模式作为源文件夹。我正在为这个项目制造一场战争。创建源jar时,目标/模式的内容也存在于该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身份验证和授权。在projectidentity中,我使用jaxb2maven插件为身份验证、授权和标识源生成xsd。由于插件jaxb2-maven-plugin仅适用于maven源路径中存在的源代码,因此我正在下载源代码以在文件夹target/schema中进行身份验证和授权,将此文件夹target/schema添加为maven-source文件夹,然后运行jaxb2-maven-plugin生成xsd。现在,当我为identity构建源jar时,它还包括我不想要的身份验证和授权源


共 (1) 个答案

  1. # 1 楼答案

    Maven Source plugin具有从创建的源JAR中排除所选文件的选项

    exclude

    List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.