2012-03-29 118 views

回答

1

经过一番深入的研究后,我发现我最好的选择是使用maven-antrun-plugin,并在过程资源阶段从类中生成一个jar文件,并将它作为依赖项添加到系统范围和systemPath中我刚刚建造的罐子。

双龙片段:

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-antrun-plugin</artifactId> 
<version>1.6</version> 
<executions> 
    <execution> 
     <phase>process-resources</phase> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     <configuration> 
      <target name="mpower.jar"> 
       <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${env.USERPROFILE}\.m2\repository\ant-contrib\ant-contrib\1.0b3\ant-contrib-1.0b3.jar"/> 

       <if> 
        <available file="${classes.dir}" type="dir"/> 
        <then> 
         <jar destfile="${env.TEMP}\classes.jar"> 
          <fileset dir="${classes.dir}\classes"> 
           <include name="**/**"/> 
          </fileset> 
         </jar> 
        </then> 
        <else> 
         <fail message="${classes.dir} not found. Skipping jar creation"/> 
        </else> 
       </if> 
      </target> 
     </configuration> 
    </execution> 
</executions> 

....

<dependency> 
     <groupId>ant-contrib</groupId> 
     <artifactId>ant-contrib</artifactId> 
     <version>1.0b3</version> 
    </dependency> 
    <dependency> 
     <groupId>com.my.code</groupId> 
     <artifactId>classes.jar</artifactId> 
     <version>1.1</version> 
     <scope>system</scope> 
     <systemPath>${env.TEMP}\classes.jar</systemPath> 
    </dependency> 
+0

非常感谢您在这里记录这一点。我有由Javassist动态生成的类,我无法在测试中使用它们。试过了Maven Build Helper插件,但它不起作用,因为我没有代码而是类文件。这是真正让我走的唯一的事情。谢谢! – khituras 2015-03-19 15:05:09