Maven 2 生成期间未启动exec maven插件目标

Maven 2 生成期间未启动exec maven插件目标,maven-2,exec-maven-plugin,Maven 2,Exec Maven Plugin,你好 在maven构建过程中,我尝试运行一个main方法。因此,我在pom.xml中添加了execmaven插件和以下代码片段 <plugin> <!-- http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ --> <groupId>org.codehaus.mojo</groupId> <artifactId>e

你好

在maven构建过程中,我尝试运行一个main方法。因此,我在pom.xml中添加了execmaven插件和以下代码片段

<plugin>
     <!-- http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ -->
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>exec-maven-plugin</artifactId>
     <version>1.1.1</version>
     <executions>
      <execution>
       <id>compile-reports</id>
       <phase>compile</phase>
       <goals>
        <goal>java</goal>
       </goals>
       <configuration>
        <mainClass>at.xyz.dls.util.JasperReportCompiler</mainClass>
       </configuration>
      </execution>
     </executions>
    </plugin>
我还尝试创建一个空的新项目来测试pom中的其他依赖是否会导致问题,但没有成功。在~/.m2文件夹中的maven settings.xml中,只有镜像条目,但没有可能导致问题的配置文件或任何其他内容

它只是不能启动它。当我删除org.codehouse下repo中的所有工件时,它没有下载execmaven插件。只有在我执行命令行调用时

有什么提示吗?提前谢谢

编辑:我忘了提到我使用过“mvn清洁安装”。所以它应该已经过了编译阶段

编辑:

到目前为止,我还不能解决这个问题。谢谢你迄今为止的回答!我会再次尝试提供所有信息,希望你们中的一个,找到可疑的部分。我再也不知道了。。。。 我所做的:

  • 删除我的maven代理中的文件夹org/codehouse/mojo。仅在加载依赖项时显示
  • 显示一些java和maven版本信息
  • 使用:mvn-clean install构建项目(应该通过测试阶段来执行我的主方法)
  • 执行main方法显示,execmaven插件仅在之后加载并工作
据我所知,调用“mvn clean install”应该通过测试阶段(测试执行…),因此应该调用exec maven插件,该插件应该执行main方法。我说得对吗

D:\Eclipse-3.6.1-JSF\ws\exec-test>java -version java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)

D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn -version Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200) Java version: 1.6.0_21 Java home: C:\Programme\Java\jdk1.6.0_21\jre Default locale: de_AT, platform encoding: Cp1252 OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows" D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn clean install 
[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Unnamed - at.test:exec-test:jar:0.0.1-SNAPSHOT 
[INFO] task-segment: [clean, install] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [clean:clean {execution: default-clean}] 
[INFO] Deleting directory D:\Eclipse-3.6.1-JSF\ws\exec-test\target 
[INFO] [resources:resources {execution: default-resources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 0 resource 
[INFO] [compiler:compile {execution: default-compile}] 
[INFO] Compiling 1 source file to D:\Eclipse-3.6.1-JSF\ws\exec-test\target\classes 
[INFO] [resources:testResources {execution: default-testResources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 0 resource 
[INFO] [compiler:testCompile {execution: default-testCompile}] 
[INFO] Compiling 1 source file to D:\Eclipse-3.6.1-JSF\ws\exec-test\target\test-classes 
[INFO] [surefire:test {execution: default-test}] 
[INFO] Surefire report directory: D:\Eclipse-3.6.1-JSF\ws\exec-test\target\surefire-reports

T E S T S

Running at.test.ExecTestTest JUnit Test call: end of junit test.


Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0


[INFO] [jar:jar {execution: default-jar}] 
[INFO] Building jar: D:\Eclipse-3.6.1-JSF\ws\exec-test\target\exec-test.jar 
[INFO] [install:install {execution: default-install}] 
[INFO] Installing D:\Eclipse-3.6.1-JSF\ws\exec-test\target\exec-test.jar to D:\maven.m2\repository\at\test\exec-test\0.0.1-SNAPSHOT\exec-test-0.0.1-SNAPSHOT.jar 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESSFUL 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3 seconds 
[INFO] Finished at: Thu Mar 10 12:07:08 CET 2011 
[INFO] Final Memory: 15M/37M 
[INFO] ------------------------------------------------------------------------ D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn exec:java -Dexec.mainClass="at.test.ExecTest" 
[INFO] Scanning for projects... 
[INFO] Searching repository for plugin with prefix: 'exec'. Downloading: http://pced06.vab.sozvers.at:8080/artifactory/repo/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.pom 6K downloaded (exec-maven-plugin-1.2.pom) Downloading: http://pced06.vab.sozvers.at:8080/artifactory/repo/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.jar 35K downloaded (exec-maven-plugin-1.2.jar) 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Unnamed - at.test:exec-test:jar:0.0.1-SNAPSHOT 
[INFO] task-segment: [exec:java] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Preparing exec:java [WARNING] Removing: java from forked lifecycle, to prevent recursive invocation. 
[INFO] No goals needed for project - skipping 
[INFO] [exec:java {execution: default-cli}]


[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESSFUL 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 7 seconds 
[INFO] Finished at: Thu Mar 10 12:07:20 CET 2011 
[INFO] Final Memory: 5M/15M 
[INFO] ------------------------------------------------------------------------        

D:\Eclipse-3.6.1-JSF\ws\exec-test>
现在再次修改pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>at.test</groupId>
  <artifactId>exec-test</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <finalName>exec-test</finalName>
    <defaultGoal>install</defaultGoal>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>
            <encoding>UTF-8</encoding>
          </configuration>
        </plugin>
        <plugin>
<!-- http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
  <execution>
    <id>compile-reports</id>
    <phase>test</phase>
    <goals>
      <goal>java</goal>
    </goals>
    <configuration>
      <mainClass>at.test.ExecTest</mainClass>
    </configuration>
  </execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.2</version>
  </dependency>
</dependencies>
和JUnit测试类:

package at.test;
import org.junit.Test;
import at.test.ExecTest;

public class ExecTestTest {

  @Test
    public void testTestTest() {
      System.err.println("JUnit Test call:");
      ExecTest.main(null);
      System.err.println("end of junit test.");
    }
}

编译阶段可能不合适,您尝试过吗

 <phase>test</phase>
测试

如果将其设置为phase compile,则必须告诉maven在运行时需要运行compile。使用maven命令无法通过任何阶段。您应该拥有
mvncileexec:java…
或更高版本(测试、安装…)

这是我对exec maven插件(使用mvn clean软件包)的用法:


org.codehaus.mojo
execmaven插件
1.2
测试
JAVA
com.xxx.LanguageGenerator
${project.build.outputDirectory}/build/PMLanguage.xls
PM${project.version}
${project.build.outputDirectory}/com/laco/projectmaster/props/resources
在maven构建期间创建(POM版本:
${project.version})

我终于找到了问题所在。这是一个相当愚蠢的错误:

在pom.xml中,我在
节点周围使用了

Maven没有抱怨,但忽略了所有插件配置。 也许有人可以利用这些信息


谢谢你的帮助

@user375251正在运行什么命令
mvn clean test
mvn clean install
?另外,由于要将exec java目标绑定到编译阶段,因此不需要将exec:java-Dexec.mainClass=“at.xyz.dls.util.JasperReportCompiler”添加到maven命令中;简单的mvn编译应该可以做到这一点。我使用它的方式完全相同,但我使用的插件版本1.2。谢谢!我也有这个问题。
package at.test;
import org.junit.Test;
import at.test.ExecTest;

public class ExecTestTest {

  @Test
    public void testTestTest() {
      System.err.println("JUnit Test call:");
      ExecTest.main(null);
      System.err.println("end of junit test.");
    }
}
 <phase>test</phase>
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.xxx.LanguageGenerator</mainClass>
                <arguments>
                    <argument>${project.build.outputDirectory}/build/PMLanguage.xls</argument>
                    <argument>PM${project.version}</argument>
                    <argument>${project.build.outputDirectory}/com/laco/projectmaster/props/resources</argument>
                    <argument>Created during maven build (POM Version:
                        ${project.version})</argument>
                </arguments>
            </configuration>
        </plugin>