【问题标题】:including Qclasses in the classpath在类路径中包括 Qclasses
【发布时间】:2014-11-09 22:06:59
【问题描述】:

我在 target/generated-sources/java 中生成我的 Qclasses,并且 Qclasses 生成良好,但是当我想在我的 src 代码 /YY/src/controller/XXX.java 中使用它们时,例如这样

QLot lot = QLot.lot;

我得到 QLot cannot be resolved to a variable 。好像生成的Qclasses不在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>

【问题讨论】:

  • 您是否在 IDE 或 Maven 中遇到此异常?
  • 我正在处理这个问题stackoverflow.com/questions/24482259/…,所以我没有按照标准说明在我的 ecipe IDE 上安装 querydsl ...我找到了一个解决方案,但我无法在类路径中包含 Qclasses但似乎@SelimOk 的答案对我有用。

标签: java spring classpath spring-data querydsl


【解决方案1】:

你可以试试这个(我假设你使用 Eclipse)。

在 pom.xml 中 - 将生成的类的目标路径设置为 /src/main/generated(目标不是一个好地方,因为每次执行 mvn clean 都会清理目标文件夹,这可能会混淆 IDE) - 可选:在块中添加生成源,以确保在预期阶段和编译前执行代码生成。

在 Eclipse 或控制台中: - 使用 mvn clean package 构建项目

在 Eclipse 项目资源管理器视图中 - 在 src/main 中找到生成的文件夹并右键单击它并选择 Build Path > Use as Source Folder。

如果您已启用“自动构建”选项,这应该可以解决“无法解析为变量”的问题。

【讨论】:

  • 谢谢它的工作,但我不明白这个Optionally: Add generate-sources in block, to ensure code generation executed at expected phase and before compilation 因为我面临这个问题stackoverflow.com/questions/24482259/… 所以我没有按照querydsl doc的说明使用maven命令。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 2012-02-21
  • 2012-09-13
  • 1970-01-01
  • 2011-12-28
相关资源
最近更新 更多