xmlbeans-maven-plugin not finding javac

[亡魂溺海] 提交于 2019-12-24 08:48:42

问题


I am trying to setup xmlbeans-maven-plugin 2.3.3 in my Eclipse and while everything seems to go OK, It fails with an java.io.IOException due to inability to find the file C:\Users\Daniel\Workspace\MyProject\javac.

This is strange because javac is on the system's %PATH% so why would it try to find it in %PROJECT_LOC%?

I found this problem description which sounds very similar to mine, but I placed the JDK path in front of all other paths and that didn't help.

Any idea how to tell the xmlbeans-maven-plugin where to look for javac?

UPDATE 1: I tried working around this problem by simply copying javac.exe to the project's directory and at least it now finds it but the problem moved forward to:

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.

Any insight that could help come up with the correct solution to this (e.g. something in .m2/settings.xml?) would be appreciated.

UPDATE 2: I also tried this little solution I found in my searches:

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

But that didn't help the plugin find javac. It still complains about "The system cannot find the file specified" for javac.exe.


回答1:


Found the solution! In the project's pom.xml, simply add the following inside <configuration>:

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

i.e.

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

Also, be sure to point the Window -> Preferences -> Java -> installed JREs to the JDK's, not JRE's: C:\Program Files (x86)\Java\jdk1.6.0_37. As described in this thread.



来源:https://stackoverflow.com/questions/13705670/xmlbeans-maven-plugin-not-finding-javac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!