【问题标题】:maven copy bat file close to the jarmaven复制bat文件靠近jar
【发布时间】:2011-11-26 18:39:04
【问题描述】:

我目前正在开发一个基于 Maven 的应用程序。我想制作一个bat文件来运行最终的jar。我已经编写了调用 java -jar... 的 bat 文件并将其放入 src/main/resources/runners 文件夹中。我也不想将此文件添加到 jar 中,因此我将其从资源插件中排除。问题是 bat 没有被复制。我已经从他们的site 复制粘贴了 maven-resources-plugin 配置,但它不起作用。但是,我只想在调用 jar:jar 时复制 bat。 应用程序托管在here,因此您可以在那里查看详细信息。我尝试这样绑定复制:

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/runners</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

还尝试了&lt;phase&gt;package&lt;/phase&gt;&lt;goal&gt;jar&lt;/goal&gt;(和&lt;goal&gt;jar:jar&lt;/goal&gt;)。没有效果。

顺便说一句:我在哪里可以更详细地阅读有关 maven 阶段和目标的信息,然后在官方文档中(从中一无所知)?

【问题讨论】:

    标签: maven maven-3 maven-resources-plugin


    【解决方案1】:

    您可以使用pre-integration-test 阶段,该阶段仅在您的 jar 由构建成功创建时才会运行。然后,您需要通过 integration-testverifyinstalldeploy 运行构建,以确保运行 copy-resources

    <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-builders</id>
                    <!-- here the phase you need -->
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/runners</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

    您可以阅读更多关于生命周期的信息:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

    【讨论】:

    • 刚试了一下,没有效果。 jar 已创建,资源已过滤,但 bat 未复制到 /target...
    • 嗯,一切正常文件,当我调用 mvn clean package 但不是当我调用 mvn clean compile jar:jar
    • 当您只运行 jar:jar 时,您将单独运行该目标。这是因为您直接指定了目标 (jar:jar)。如果引用生命周期阶段之一(打包或安装),则将运行直到并包括该生命周期阶段的所有生命周期阶段。
    • 我明白了,但感谢您的回复。现在我又遇到了 maven 的问题:stackoverflow.com/q/8281941/750510
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多