塞尔玛代码生成

时间:2016-08-05 09:46:27

标签: java maven

enter image description here

根据https://github.com/xebia-france/selma/blob/master/examples/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>com.mapper</groupId>
    <artifactId>Selma</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.bsc.maven</groupId>
                    <artifactId>maven-processor-plugin</artifactId>
                    <version>2.2.4</version>
                    <configuration>
                        <defaultOutputDirectory>
                            ${project.build.directory}/generated-sources/selma
                        </defaultOutputDirectory>
                        <processors>
                            <processor>fr.xebia.extras.selma.codegen.MapperProcessor</processor>
                        </processors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>process</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>process</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>fr.xebia.extras</groupId>
                            <artifactId>selma-processor</artifactId>
                            <version>${project.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>fr.xebia.extras</groupId>
                            <artifactId>example-common</artifactId>
                            <version>0.16-SNAPSHOT</version>
                        </dependency>
                    </dependencies>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <executions>
                        <execution>
                            <id>add-source</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>${project.build.directory}/generated-sources/selma</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>fr.xebia.extras</groupId>
            <artifactId>selma-processor</artifactId>
            <version>0.15</version>
            <scope>provided</scope>
        </dependency>

        <!-- This is the only real dependency you will have in your binaries -->
        <dependency>
            <groupId>fr.xebia.extras</groupId>
            <artifactId>selma</artifactId>
            <version>0.15</version>
        </dependency>
    </dependencies>
</project>

我创建了一个selma示例,但无法生成代码。运行时出现错误

Caused by: java.lang.ClassNotFoundException:com.mapper.mapper.SelmaMapperSelmaGeneratedClass

是否应该添加其他配置来生成代码?

2 个答案:

答案 0 :(得分:0)

我误解了编译时的意思,的确,我应该运行maven命令clean install。然后生成代码。

答案 1 :(得分:0)

在没有Maven的情况下在eclipse中使用Selma,你应该将处理器和api jar添加到注释处理器插件的路径中。 这应该在项目设置中的某处,请参阅插件文档: https://www.eclipse.org/jdt/apt/introToAPT.php