2010-09-06 63 views
0

我想通过maven-2在项目目标文件夹的特定位置(特别是在target/abc_project/META-INF文件夹中)创建一个build info文件。如何从pom.xml执行jar

以下是我在做什么在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> 

而不是install, deploy给予phase其他,我碰到下面的错误 -

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

+0

你的项目有一些奇怪的东西。你改变了默认值吗? target \ abc_project \ META-INF \ info.txt应该从哪里来? – 2010-09-06 20:16:33

回答

0

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

+0

是的..这是真的,它不是直到那时创建abc_project文件夹本身,而是使用安装/部署以外的阶段。我不知道为什么它是如此......如果有人能告诉我什么时候在maven中创建完整的目标文件夹(具有所有必需的相关文件夹),那么这将非常有用。 – deejay 2010-09-06 09:46:20

+0

在编译阶段创建project.build.directory(默认:“target”)和project.build.outputDirectory(默认值:“target/classes”)。您是否已将project.build.outputDirectory属性更改为“target \ abc_project”? – Jcs 2010-09-06 10:12:55