You need to run build with JDK or have tools.jar on the classpath

在配置QueryDSL的时候报的这个错误,在 stackoverflow.com 上找到了2个questions,按里面给出的答案修改后可用。

https://stackoverflow.com/questions/27619304/you-need-to-run-build-with-jdk-or-have-tools-jar-on-the-classpath

https://stackoverflow.com/questions/24482259/eclipse-issue-with-maven-build-and-jdk-when-generating-qclasses-in-querydsl

报错信息

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.1.3:process:default:generate-sources) org.apache.maven.plugin.MojoExecutionException: 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 at
com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:362) at
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at
org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331) at org.eclipse.m2e.core.internal.embedder.MavenImpl
$11.call(MavenImpl.java:1362) at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112) at
org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360) at
org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52) at
org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:137) at org.eclipse.m2e.core.internal.builder.MavenBuilder
$1.method(MavenBuilder.java:172) at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1) at
org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1$1.call(MavenBuilder.java:115) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112) at
org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:105) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99) at
org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86) at
org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200) at org.eclipse.core.internal.events.BuildManager
$2.run(BuildManager.java:734) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at
org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205) at
org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245) at org.eclipse.core.internal.events.BuildManager
$1.run(BuildManager.java:300) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at
org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303) at
org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359) at
org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:
1) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) Caused by:
org.apache.maven.plugin.MojoExecutionException: 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 at com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:310) ... 32 more

方案一配置eclipse.ini

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

因为我用的是STS,所以在STS.ini里面加了这个配置,但是没用。

方案二,添加dependency

<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>

原答案里写的是

<systemPath>${java.home}/../lib/tools.jar</systemPath>

不知道这是个什么路径,总之这个路径能找到tools.jar就行,如果没有配置环境变量,也可以使用C:/Program Files/Java/jdk1.8.0_101/lib/tools.jar

分享到