【问题标题】:How to execute a jar from pom.xml如何从 pom.xml 执行 jar
【发布时间】:2011-04-08 15:54:16
【问题描述】:

我想通过maven-2在项目的目标文件夹(尤其是target/abc_project/META-INF文件夹)的特定位置创建一个构建信息文件。

以下是我在 pom.xml 中所做的事情

<build>
    <finalName>abc_project</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
 <execution>
  <phase>package</phase>
  <id>buid-info-generator</id>
  <goals>
   <goal>exec</goal>
  </goals>
  <configuration>
  <executable>java</executable>
   <arguments>
    <argument>-jar</argument>
    <argument>xyz.jar</argument>
    <argument>target/abc_project/META-INF/info.txt</argument>
    <argument>date</argument>
    <argument>hg summary</argument>
   </arguments>
  </configuration>
 </execution>
</executions>

    </plugins>
</build>

在提供phase 以外的install, deploy 时,我收到以下错误 -

[INFO] Exception in thread "main" java.io.FileNotFoundException: target\abc_project\META-INF\info.txt (The system cannot find the path specified)
[INFO]  at java.io.FileOutputStream.open(Native Method)
[INFO]  at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
[INFO]  at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
[INFO]  at java.io.FileWriter.<init>(FileWriter.java:73)
[INFO]  at com.nbec.svn.build.info.BuildInfoGenerator.main(BuildInfoGenerator.java:30)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Result of cmd.exe /X /C "java -jar xyz.jar target/abc_project/META-INF/info.txt "date "hg summary"" execution is: '1'.

但奇怪的是,相同的代码适用于 1 个项目,而不适用于其他 2 个项目。有没有其他方法可以获得相同的。

【问题讨论】:

  • 您的项目有些奇怪。您是否更改了默认值? target\abc_project\META-INF\info.txt 应该来自哪里?

标签: maven-2 pom.xml command-execution


【解决方案1】:

实际上错误报告表明目录target\abc_project\META-INF可能不存在。没有更多信息,我只能推测。也许创建abc_project\META-INF 目录的插件是在exec-maven-plugin 之后调用的。

【讨论】:

  • 是的.. 没错,直到那时它才创建 abc_project 文件夹本身,同时使用安装/部署以外的阶段。我不知道为什么会这样..如果有人能告诉我何时在 maven 中创建完整的目标文件夹(以及所有必需的依赖文件夹),那将是非常棒的。
  • project.build.directory(默认:“target”)和project.build.outputDirectory(默认:“target/classes”)是在编译阶段创建的。您是否将 project.build.outputDirectory 属性更改为“target\abc_project”?
猜你喜欢
  • 1970-01-01
  • 2016-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-30
  • 1970-01-01
  • 2019-09-06
相关资源
最近更新 更多