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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24482259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:27:33  来源:igfitidea点击:

Eclipse issue with Maven build and JDK when generating Qclasses in Querydsl

javaeclipsemavenquerydsl

提问by Youssef

When I add this code below in my pom.xmlto support 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>

I got this error when building with Eclipse. I think it has relation with classpath and JDK jars

使用 Eclipse 构建时出现此错误。我认为它与类路径和 JDK jars 有关系

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)

.classpath:

.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>


Extra info :


额外信息:

enter image description here

在此处输入图片说明

My maven Installation

我的maven安装

enter image description here

在此处输入图片说明

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

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

采纳答案by Youssef

SOLUTION 1

解决方案 1

Following this link

按照这个链接

"The Maven APT plugin has a known issue that prevents its usage directly from Eclipse. Eclipse users must create the Querydsl query types manually by running the command mvn generate-sources at command prompt."

“Maven APT 插件有一个已知问题,阻止它直接从 Eclipse 使用。Eclipse 用户必须通过在命令提示符下运行命令 mvn generate-sources 手动创建 Querydsl 查询类型。”

So i execute the command line mvn generate-sourcesin my project floder with console cmdand i got my Qclasses generated.

所以我mvn generate-sources使用控制台在我的项目cmdfloder 中执行命令行,并生成了我的 Qclasses。

SOLUTION 2from @informatik01 comment

来自@informatik01 评论的解决方案 2

we can explicitly specified JVMin the eclipse.inilike that :

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

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

-vmargs
...

The -vmoption must occur before the -vmargsoption and for more info read @informatik01 comment below.

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

回答by user3313007

If you build by shell commond like mvn install. Then run this command in the shell or cmd window: echo $CLASSPATH. This command shows your classpath.

如果您通过像 mvn install 这样的 shell commond 构建。然后在 shell 或 cmd 窗口中运行此命令:echo $CLASSPATH。此命令显示您的类路径。

If you are using Eclipse, open Window > Preferences > Java > Installed JREs, make sure your installed JREs are of jdk root location. For me, it is C:\Java\jdk1.7.0_51

如果您使用的是 Eclipse,请打开 Window > Preferences > Java > Installed JREs,确保您安装的 JREs 位于 jdk 根位置。对我来说,它是 C:\Java\jdk1.7.0_51

Hope it helps.

希望能帮助到你。

回答by Karibasappa G C

Try updating the JDK in Eclipse as below:

尝试在 Eclipse 中更新 JDK,如下所示:

set the JRE in

将 JRE 设置为

look at the path below - having program files(but in your mentioned path it is not having program filesin your path , usually java and all programs gets install in program filesso make sure that path)

看看下面的路径 - 有program files(但在你提到的路径中它没有 program files在你的路径中,通常是java和所有程序都被安装,program files所以确保路径)

 Window->Preferences...->Java->Installed JREs:

JRE type: Standard VM JRE 
Name: jdk1.6.0_18
JRE home directory: C:\Program Files (x86)\Java\jdk1.6.0_18

alos make sure JAVA_HOMEpath is set properly to JDK\binproperly(without any spaces and all in that path)

alos 确保JAVA_HOME路径设置正确JDK\bin(没有任何空格和路径中的所有内容)

Try copying your JDKto a different location and update your JAVA_HOMEwith that new location.

尝试将您的复制JDK到其他位置并JAVA_HOME使用该新位置更新您的位置。

let me know for any other issues.

让我知道任何其他问题。

回答by eis

You could try with this in the pom:

你可以在 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>

And see if it changes anything. It should force tools.jar in the build path.

看看它是否改变了什么。它应该在构建路径中强制 tools.jar。



Edit. since that didn't help, try specifying

编辑。因为那没有帮助,请尝试指定

-vm 
D:/work/Java/jdk1.6.0_13/bin/javaw.exe

in eclipse.ini (separate lines are important), as explained in this thread.

在 eclipse.ini 中(单独的行很重要),如该线程中所述

回答by Hartmut P.

Don't forget to check the setting of the Execution Environmentin in your Eclipse Project Settings: Project Build Path -> Libraries -> JRE System Library.

不要忘记在 Eclipse Project Settings: Project Build Path -> Libraries -> JRE System Library 中检查Execution Environment 的设置。

If this is wrong (e.g. jre), switch this to a jdkone.

如果这是错误的(例如jre),请将其切换为jdk

In my case, this solved the issue ("You need to run build with JDK or have tools.jar on the classpath." disappeared).

就我而言,这解决了问题(“您需要使用 JDK 运行构建或在类路径上安装 tools.jar。”消失了)。

Then the approx. fourth line in the Maven Run Log changes from (e.g.)

然后大约。Maven 运行日志中的第四行更改自(例如)

...
Java home: C:\Program Files\Java\jre1.8.0_66
....

to

 ...
 Java home: C:\Program Files\Java\jdk1.8.0_66\jre
 ...

Hope this helps.

希望这可以帮助。

回答by chenyayi

<groupId>com.mysema.maven</groupId>
        <artifactId>maven-apt-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.JAPAnnotationProcessor</processor>
                </configuration>
            </execution>
        </executions>
    </plugin>

add the plugin ,you will solve it

添加插件,你会解决它

回答by River

This issue was happening to me because as mentioned above, Eclipse itself was running through the JRE instead of the JDK.

这个问题发生在我身上,因为如上所述,Eclipse 本身是通过 JRE 而不是 JDK 运行的。

I solved it by adding %JAVA_HOME%\binto the front of my PATH environment variable.

我通过在 PATH 环境变量的前面添加%JAVA_HOME%\bin来解决它。

I figured out what JVM eclipse was using by reading through: Find out what JVM Eclipse is running on

我通过阅读了解了 JVM Eclipse 正在使用的内容:找出运行的 JVM Eclipse

回答by RVP

I had done everything suggested above but to no avail. Finally, because I was setting up a new computer, I realized I didn't have a JAVA_HOMEvariable set up.

我已经完成了上面建议的所有操作,但无济于事。最后,因为我正在设置一台新计算机,我意识到我没有JAVA_HOME设置变量。

So all I did was to add the JAVA_HOMEvariable to my system variables and set that to a JDK path: C:\Program Files\Java\jdk1.8.0_172

所以我所做的就是将JAVA_HOME变量添加到我的系统变量中并将其设置为 JDK 路径:C:\Program Files\Java\jdk1.8.0_172

And voila - mvn generate-resourcesstarted working again.

瞧——又mvn generate-resources开始工作了。

回答by claraind

I did it finally! I've tried so many option like thisand this, but no luck. Then I read this commentthat saved my life, really, thank you! I follow this solution and its working suddenly! should be accepted answer in my case.

我终于做到了!我已经尝试了很多像这样这样的选择,但没有运气。然后我看了这条救了我一命的评论,真的,谢谢!我遵循这个解决方案并且它突然工作了!在我的情况下应该接受答案。

I copied tools.jar from C:\Program Files\Java\jdk1.8.0_151\lib to C:\Program Files\Java\jre1.8.0_151\lib, after i execute mvn clean install – @julio mulcue burbano

在我执行 mvn clean install 之后,我将 tools.jar 从 C:\Program Files\Java\jdk1.8.0_151\lib 复制到 C:\Program Files\Java\jre1.8.0_151\lib – @julio mulcue burbano