1

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>
Hayi
  • 6,972
  • 26
  • 80
  • 139
  • Do you get this exception in an IDE or in Maven? – Timo Westkämper Nov 19 '14 at 18:17
  • i was running through this issue http://stackoverflow.com/questions/24482259/eclipse-issue-with-maven-build-and-jdk so i didn't follow the standard instruction to install querydsl on my eclipe IDE ... i found a solution but i have problem to including Qclasses in the classpath but it seem that the answer of @SelimOk work for me. – Hayi Nov 19 '14 at 21:05

1 Answers1

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.

enter image description here

This should fix "cannot be resolved to a variable" problems if you already enabled "Build Automatically" option.

Selim Ok
  • 1,141
  • 1
  • 7
  • 21
  • thanks it work but i didn't understand this `Optionally: Add generate-sources in block, to ensure code generation executed at expected phase and before compilation` for the info i was facing this issue http://stackoverflow.com/questions/24482259/eclipse-issue-with-maven-build-and-jdk so i didn't use maven commands as in instruction of querydsl doc. – Hayi Nov 19 '14 at 22:54