gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:22:55 25 4
gpt4 key购买 nike

我有一个用例,我需要使用 maven-buildHelper 插件将文件夹 target/schemas 包含为源文件夹。我正在为这个项目制造一场 war 。当源 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 源路径中存在的源,我正在下载文件夹 target/schema 中的身份验证和授权源,将此文件夹 target/schema 添加为 maven 源文件夹,然后运行 ​​jaxb2 -maven-plugin 生成xsd。现在,当我为身份构建源 jar 时,它还包含我不需要的身份验证和授权源。

最佳答案

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.

关于java - 在 Maven 中,添加一个文件夹作为源文件夹,但不要将其包含在源 jar 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21475859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com