在Querydsl中生成Qclasses时,Maven构建和JDK的Eclipse问题

You*_*sef 24 java eclipse maven querydsl

当我在下面添加此代码pom.xml以支持Querydsl时

<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>
Run Code Online (Sandbox Code Playgroud)

使用Eclipse构建时出现此错误.我认为它与classpath和JDK jar有关系

You need to run build with JDK or have tools.jar on the classpath.
If this occures during eclipse build make sure you run eclipse under  JDK as well 
(com.mysema.maven:apt-maven-plugin:1.0.6:process:default:generate-sources)
Run Code Online (Sandbox Code Playgroud)

.classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
Run Code Online (Sandbox Code Playgroud)


额外信息:

在此输入图像描述

我的maven安装

在此输入图像描述

JAVA_HOME:C:\ Program Files\Java\jdk1.7.0_45
路径:%JAVA_HOME%\ bin;

You*_*sef 46

解决方案1

点击此链接

"行家APT插件有一个已知的问题,直接阻止其使用从Eclipse中.Eclipse用户必须通过运行在命令提示命令MVN产生来源手动创建Querydsl查询类型".

所以我mvn generate-sources在我的项目floder中使用控制台执行命令行,cmd然后生成了我的Qclasses.

解决方案2来自@ informatik01评论

我们可以明确地指定JVMeclipse.ini这样的:

-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe

-vmargs
...
Run Code Online (Sandbox Code Playgroud)

-vm选项必须在-vmargs选项之前发生,有关更多信息,请阅读下面的@ informatik01评论.


eis*_*eis 5

你可以在pom中试试这个:

<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>
  <dependencies>
    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.7</version>
      <scope>system</scope>
      <systemPath>${java.home}/../lib/tools.jar</systemPath>
     </dependency>
  </dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)

并看看它是否有任何改变.它应该在构建路径中强制tools.jar.


编辑.既然没有帮助,请尝试指定

-vm 
D:/work/Java/jdk1.6.0_13/bin/javaw.exe
Run Code Online (Sandbox Code Playgroud)

在eclipse.ini中(单独的行很重要),如本主题中所述.