问题
I generate My Qclasses in target/generated-sources/java
and the Qclasses are generating good but when i want to use them in my src code /YY/src/controller/XXX.java
for example like that
QLot lot = QLot.lot;
I get QLot cannot be resolved to a variable
. It seems that the generated Qclasses are not in the classpath !!
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.0.6</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
回答1:
You may try this (I assume you use Eclipse).
in pom.xml - Set the target path of the generated classes as /src/main/generated (target is not a good place, because everytime you execute mvn clean the target folder will be cleaned and this may confuse IDEs) - Optionally: Add generate-sources in block, to ensure code generation executed at expected phase and before compilation.
in Eclipse or in console: - Build the project with mvn clean package
in Eclipse Project Explorer view - Find generated folder in src/main and right click on it and select Build Path > Use as Source Folder.

This should fix "cannot be resolved to a variable" problems if you already enabled "Build Automatically" option.
来源:https://stackoverflow.com/questions/26833880/including-qclasses-in-the-classpath