4

我正在尝试学习如何将 Neo4j 密码与 QueryDSL 一起使用。所以我从neo4j/cypher-dsl GitHub 存储库下载了源代码,并将项目作为Maven 项目导入到 eclipse 中。但是,当我尝试编译和运行测试时,我收到一堆无法解析 Q{Something} 类的错误,例如:

QPerson cannot be resolved to a type

这是一个屏幕截图:

在此处输入图像描述

我忘了配置什么吗?我找不到任何关于它的教程或任何说明我需要做任何特别的事情......

怎么了?

谢谢!

4

1 回答 1

6

那些“Q”文件需要由QueryDSL 生成。“maven-apt-plugin”会处理这个问题。下面的 pom 显示了您需要的内容:

<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.github.timmystorms</groupId>
    <artifactId>neo4j-querydsl</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>maven-apt-plugin</artifactId>
                <version>1.0.4</version>
                <configuration>
                    <processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
                </configuration>
                <executions>
                    <execution>
                        <id>sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>src/main/java</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.mysema.maven</groupId>
                                        <artifactId>maven-apt-plugin</artifactId>
                                        <versionRange>[1.0.2,)</versionRange>
                                        <goals>
                                            <goal>process</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>1.9.RC1</version>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher-dsl</artifactId>
            <version>1.9.M04</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-lucene</artifactId>
            <version>2.8.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Optional test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

查看我的Gist测试此设置。只需使用您的代码构建例如mvn clean install.

编辑:确保在构建时指向 JDK 而不是 JRE,因为 maven-apt-plugin 需要 tools.jar。

于 2013-05-07T07:38:26.320 回答