简体   繁体   中英

Generated Classes by JAXB are not recognizable

I am trying JAXB for xml mapping in a Maven project. I put JAXB jar in a separated project and add it as a dependency to my main project. I am using Eclipse.

Now the functionality of JAXB seems fine and from some XSD schema several Java classes are generated in target/generated-sources/xjc folder. The problem is Eclipse cannot resolve those classes in unit testing in main project. I even manually import those package name but still the class names are not resolvable. Is there anything I am missing?

You can add the generated source files to the build path by Right click -> Build Path -> Use as source folder on the folder with generated resources.

As stated in the comments the plugin you are using should automatically do this for you. In case it doesn't you can use the build-helper-maven-plugin ( related question ) with the following configuration:

<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/xjc</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM