我正在尝试学习如何在QueryDSL中使用Neo4j cypher。所以我从neo4j/cypher-dsl GitHub repository下载了源代码,并将项目作为 Maven项目导入到eclipse中。但是,当我尝试编译并运行测试时,我得到了一堆Q {Something}类无法解决的错误,例如:
QPerson cannot be resolved to a type
以下是截图:
我忘了配置一些东西吗?我找不到任何关于它的教程或任何声明我需要做任何特别的事情......
有什么问题?
谢谢!
答案 0 :(得分:5)
这些“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。