簡體   English   中英

在Querydsl中生成Qclass時,Maven build和JDK的Eclipse問題

[英]Eclipse issue with Maven build and JDK when generating Qclasses in 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>

使用Eclipse進行構建時出現此錯誤。 我認為它與classpath和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

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


額外信息:

在此處輸入圖片說明

我的Maven安裝

在此處輸入圖片說明

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

解決方案1

跟隨此鏈接

“ Maven APT插件存在一個已知問題,無法直接在Eclipse中使用它。Eclipse用戶必須通過在命令提示符處運行命令mvn generate-sources來手動創建Querydsl查詢類型。”

因此,我使用控制台cmd在我的項目選單中執行了命令行mvn generate-sources ,並且生成了Qclasses。

來自@ informatik01的解決方案2注釋

我們可以像這樣在eclipse.ini明確指定JVM

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

-vmargs
...

-vm選項必須出現在-vmargs選項之前,有關更多信息,請閱讀下面的@ informatik01注釋。

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

看看它是否有任何改變。 它應該在構建路徑中強制使用tools.jar。


編輯。 既然沒有幫助,請嘗試指定

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

eclipse.ini中的命令(分隔線很重要),如本線程中所述

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

添加插件,您將解決它

我遇到了這個問題,因為如上所述,Eclipse本身通過JRE而不是JDK運行。

我通過在PATH環境變量的前面添加%JAVA_HOME%\\ bin來解決此問題。

通過閱讀以下內容,我弄清楚了正在使用什么JVM eclipse: 查找正在運行什么JVM Eclipse。

我終於做到了! 我試過這么多的選項像這樣這個 ,但沒有運氣。 然后,我閱讀了挽救了我生命的評論 ,真的,謝謝! 我遵循此解決方案,它突然起作用了! 在我的情況下應該被接受的答案。

執行mvn全新安裝后,我將tools.jar從C:\\ Program Files \\ Java \\ jdk1.8.0_151 \\ lib復制到C:\\ Program Files \\ Java \\ jre1.8.0_151 \\ lib – @julio mulcue burbano

如果您使用像mvn install這樣的shell commond進行構建。 然后在shell或cmd窗口中運行以下命令:echo $ CLASSPATH。 此命令顯示您的類路徑。

如果使用的是Eclipse,請打開“窗口”>“首選項”>“ Java”>“已安裝的JRE”,請確保已安裝的JRE具有jdk根目錄。 對我來說是C:\\ Java \\ jdk1.7.0_51

希望能幫助到你。

嘗試如下所示在Eclipse中更新JDK:

將JRE設置在

查看下面的路徑-具有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

請確保將JAVA_HOME路徑正確設置為JDK\\bin (在該路徑中沒有任何空格,並且所有空格都正確)

嘗試將JDK復制到其他位置,然后使用該新位置更新JAVA_HOME

讓我知道其他任何問題。

不要忘記在Eclipse Project Settings中檢查Execution Environment的設置: Project Build Path-> Libraries-> JRE System Library

如果這是錯誤的(例如jre ),請將其切換為一個jdk

就我而言,這解決了問題(“您需要使用JDK運行構建或在類路徑上具有tools.jar。”消失了)。

然后約。 Maven運行日志中的第四行從(例如)更改

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

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

希望這可以幫助。

我已經做了上面建議的一切,但都無濟於事。 最后,因為我正在設置一台新計算機,所以我意識到沒有設置JAVA_HOME變量。

因此,我C:\\Program Files\\Java\\jdk1.8.0_172就是將JAVA_HOME變量添加到系統變量中並將其設置為JDK路徑: C:\\Program Files\\Java\\jdk1.8.0_172

mvn generate-resources重新開始工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM