-->

JAXB2-maven only builds in target

2019-06-24 02:36发布

问题:

I'm on my first Java-Spring project. I need to communicate with a couple of webservices. I have some WSDL's provided, so i'm using Jax2B to autogenerate classes.

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.9.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <forceRegenerate>true</forceRegenerate>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>

                </configuration>
</plugin>

My project is a web project. The problem here is, my classes are generated in the targets folder, and not in my project. Does somebody have ideas how to fix this? Classes are generated properly, but not at the proper directory. As you can see, i'm using a test wsdl and mockup names at the moment. I followed this tutorial: http://spring.io/guides/gs/consuming-web-service/

Many thanks in advance

回答1:

Author of the maven-jaxb2-pugin here.

target/generated-sources/xjc IS the proper directory. This is how generated code is handled in Maven builds, you never generate anything into src/main/java.

The maven-jaxb2-plugin also adds this directory to the Maven's sources directories. You just have to make sure that this directory is considered a source directory by your IDE. In Eclipse, m2eclipse plugin does this automatically when you do "Update project".

See this part of the docs.



回答2:

I use this plugin to add the classes generated to source....

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.1</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>