java - under - you need to run build with jdk or have tools jar on the classpath pom xml




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

<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

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

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>


Extra info :

My maven Installation

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


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

So i execute the command line mvn generate-sources in my project floder with console cmd and i got my Qclasses generated.

SOLUTION 2 from @informatik01 comment

we can explicitly specified JVM in the eclipse.ini like that :

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

-vmargs
...

The -vm option must occur before the -vmargs option and for more info read @informatik01 comment below.


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_HOME variable set up.

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

And voila - mvn generate-resources started working again.


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.

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

Hope it helps.


Try updating the JDK in Eclipse as below:

set the JRE in

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

 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_HOME path is set properly to JDK\bin properly(without any spaces and all in that path)

Try copying your JDK to a different location and update your JAVA_HOME with that new location.

let me know for any other issues.


You could try with this in the 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.


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.





querydsl