如何从 pom.xml 执行 jar

发布于 2024-09-17 16:20:29 字数 2314 浏览 5 评论 0原文

我想通过 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>

同时给出除安装、部署之外的阶段,我收到以下错误 -

[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 个项目。有没有其他方法可以获得相同的效果。

I want to create a build info file into the specific location of the project's target folder (especially in target/abc_project/META-INF folder) through maven-2.

Following is what I am doing in the 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>

while giving the phase other than install, deploy, I get the following error -

[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'.

But strangely, the same code is working for 1 project and not for other 2 projects. Is there any alternative to obtain the same.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蔚蓝源自深海 2024-09-24 16:21:14

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

Actually the error report indicates that the directory target\abc_project\META-INF probably does not exist. Without more information I can only speculate. Maybe the plugin which create the abc_project\META-INF directory is called after the exec-maven-plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文