How does one get JAXB-generated sources onto the Eclipse build path under m2e/Indigo?

故事扮演 提交于 2019-11-29 23:32:02
Eric

In Eclipse go to "Install New Software" add the software site: http://bitstrings.github.com/m2e-connectors-p2/releases/

Select the "m2e connector for jaxb2"

Once you get that plugin installed the jaxb2 plugin should integrate correctly with the new version of m2e.

This info is from: https://bugs.eclipse.org/bugs/show_bug.cgi?id=350299

Well, you need to right click on the "target/generated-sources/xjc and select something like "Build Path -> Use as source folder"

As an alternate workaround if you can't get the m2e connector working, you can add the generated sources to the build path with build-helper-maven-plugin:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <version>1.7</version>
      <executions>
        <execution>
          <id>add-source</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>add-source</goal>
          </goals>
          <configuration>
            <sources>
              <source>target/generated-sources/xmlbeans</source>
            </sources>
          </configuration>
        </execution>
      </executions>
    </plugin>
    ...     
  </plugins>
  ... 
</build>

While waiting for a fix for this problem, I'm using the following temporary workaround:

We have the jaxb-plugin and generated classes in a separate maven module. In eclipse I can then "disable Maven nature" on that module only. Then I can use Indigo with m2eclipse on the rest of our large maven project and it will depend on the jar for the jaxb module (must be built from the command line). This works well for me since our project was allready organized this way.

Michael-O

For those who are suffering with maven-jaxb2-plugin and Eclipse not having source attached. The author has switched from the Sun to the Glassfish JAXB artifacts and the dependency tree has changed. Previously many JARs where shaded into jaxb-xjc without transitive ones. Now, this has been removed and the previous transitive dependency to tools.jar breaks Eclipse execution. Start your Eclipse with a JDK VM and it will work. (Tested most recent Maven 3.3.9, Maven JAXB2 Plugin 0.13.1, recent m2e JAXB2 connector and Eclipse Mars.2)

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