簡體   English   中英

如何使用Maven將生成的文件從依賴項復制到當前項目的目標?

[英]How to copy a generated files from a dependency to the target of current project with maven?

我已經拖走了Maven項目resources-winmain-exec 。我嘗試從resources-win的文件夾win中復制一個dll文件,並將其復制到target/classes ,然后我移到項目編號2 main-exec然后嘗試將文件2復制到src/main/shcemas然后將resources-win的dll文件粘貼到項目resources-win目標類中

這是代碼塊幫助將文件復制到resources-win目標的塊:

<plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>copy-resources01</id>
                <phase>process-classes</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                    <encoding>UTF-8</encoding>
                    <resources>
                        <resource>
                            <directory>${basedir}/src/main/win</directory>
                            <includes>
                                <include>**/*.dll</include>
                            </includes>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>

這是項目main-exec的pom.xml的一部分:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-libraries</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <!-- win32 -->
                            <artifactItem>
                                <groupId>com.resources-win</groupId>
                                <artifactId>ressources-win</artifactId>
                                <version>1.0.0-SNAPSHOT</version>
                                <type>pom</type>
                                <destFileName>xdol.dll</destFileName>
                                <outputDirectory>${project.build.directory}/temp/schemas</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我這樣做是通過將xsd文件添加到resources-win pom.xml中來resources-win

<plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources-xsd</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        <encoding>UTF-8</encoding>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/schemas</directory>
                                <includes>
                                    <include>**/*.xsd</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-artifacts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>${project.build.outputDirectory}/titi.xsd</file>
                                <type>xsd</type>
                                <classifier>titi</classifier>
                            </artifact>
                            <artifact>
                                <file>${project.build.outputDirectory}/toto.xsd</file>
                                <type>xsd</type>
                                <classifier>toto</classifier>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>

然后添加到main-exec的pom.xml中:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-libraries</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>groupId of resources-win</groupId>
                                <artifactId>artifactId of resources-win</artifactId>
                                <version>${resources-win.version}</version>
                                <type>xsd</type>
                                <classifier>toto</classifier>
                                <destFileName>toto.xsd</destFileName>
                                <outputDirectory>${project.build.directory}/tmp/schemas</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我還添加了main-exec的pom.xml,它依賴資源雙贏。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM