【问题标题】:Maven shaded plugin replacing persistence.xmlMaven 阴影插件替换 persistence.xml
【发布时间】:2018-10-13 11:27:36
【问题描述】:

在 maven 包期间,我有一个奇怪的行为。我有一个依赖于“B”的工件“A”。

在“A”中,我有一个 META-INF 文件夹,其中包含一个 persistence.xml,在“B”中,我有一个 META-INF 文件夹,其中包含一个 persistence.xml。

这是 pom 的 A 相对于 shade 插件和依赖的文件

    <dependency>
        <groupId>com.mycopany</groupId>
        <artifactId>B</artifactId>
        <version>1.0.2</version>
       </dependency>
   </dependencies>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
                <shadedArtifactAttached>true</shadedArtifactAttached>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

考虑到“B”也是阴影工件,我如何从“B”中排除 persistence.xml 文件?

【问题讨论】:

    标签: java maven maven-plugin maven-shade-plugin


    【解决方案1】:

    使用第二个过滤器并像这样排除 persistence.xml

                    <filter>
                        <artifact>B</artifact>
                        <excludes>
                            <exclude>path/persistence.xml</exclude>  
                        </excludes>
                    </filter>
    

    更多细节在这个question 并在official documentation

    【讨论】:

    • 不知何故这对我不起作用。你能举个“路径”的例子吗?
    【解决方案2】:

    我找到的一个解决方案是在没有 persistence.xml 配置文件的情况下创建 JPA EntityManager。 我使用了 PersistenceUnitInfo。

    这是原帖:Create JPA EntityManager without persistence.xml configuration file

    【讨论】:

    猜你喜欢
    • 2012-03-06
    • 2015-07-29
    • 1970-01-01
    • 2013-11-17
    • 2021-05-01
    • 1970-01-01
    • 2021-02-22
    • 2018-11-27
    • 2022-06-28
    相关资源
    最近更新 更多