1

我正在尝试在我的 Eclipse 中设置xmlbeans-maven-plugin 2.3.3,虽然一切似乎都正常,但由于无法找到文件而失败并出现 java.io.IOException C:\Users\Daniel\Workspace\MyProject\javac

这很奇怪,因为 javac系统的 %PATH% 上,为什么它会尝试在 %PROJECT_LOC% 中找到它?

我发现这个问题描述听起来与我的非常相似,但是我将 JDK 路径放在所有其他路径的前面,但这并没有帮助。

知道如何告诉在xmlbeans-maven-plugin 哪里寻找javac吗?

更新1:我尝试通过简单地复制javac.exe到项目目录来解决这个问题,至少它现在找到了它,但问题转移到了:

java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main" Could not find the main class: com.sun.tools.javac.Main.  Program will exit.

任何可以帮助提出正确解决方案的见解(例如.m2/settings.xml 中的内容?)将不胜感激。

更新 2:我还尝试了在搜索中找到的这个小解决方案:

<settings xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>c:\maven\repository</localRepository>
   <configuration>
    <compiler>C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe</compiler>
   </configuration>
</settings>

但这并没有帮助插件找到javac. 它仍然抱怨 javac.exe 的“系统找不到指定的文件”。

4

1 回答 1

2

找到了解决方案!在项目的pom.xml 中,只需在里面添加以下内容<configuration>

<compiler>C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe</compiler>

IE

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xmlbeans-maven-plugin</artifactId>
            <version>2.3.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>xmlbeans</goal>
                    </goals>
                </execution>
            </executions>
            <inherited>true</inherited>
            <configuration>
                <schemaDirectory>${basedir}/src/main/xsd</schemaDirectory>
                <compiler>C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe</compiler>
            </configuration>
        </plugin>

此外,请务必将 指向Window -> Preferences -> Java -> installed JREsJDK,而不是 JRE: C:\Program Files (x86)\Java\jdk1.6.0_37。如该线程中所述。

于 2012-12-04T16:12:05.100 回答