我是个新手,刚开始使用JCodeModel。谁能为我提供一个简单的演示或链接如何在maven项目中使用JCodeModel?我需要把JCodeModel类放在maven的什么地方才能生成java类?
发布于 2013-01-07 15:07:24
我最终使用了两个不同的maven插件来实现这一点。首先,我使用maven ant插件来编译我的codemodel代码。然后,我使用exec插件运行codemodel代码,以便maven构建可以构建生成的类作为构建的一部分。我把maven代码放在下面:
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>1</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<mkdir dir="${basedir}/target/classes" />
<javac srcdir="${basedir}/src/main/java/com/generation/" destdir="${basedir}/target/classes" classpathref="maven.compile.classpath">
</javac>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>2</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>com.generation.CodeGeneration</argument>
</arguments>
</configuration>
</plugin>
</plugins>https://stackoverflow.com/questions/10558817
复制相似问题