d-man
d-man

Reputation: 58103

unable to generate jaxb .xsd to java classes in goal phase

Java - jaxb - maven plugin

I have maven based web application, in pom i have following plugin which should generate jaxb .xsd to java classes.

When i execute clean, compile, package xsd classes do not gets generate. When i execute mvn jaxb2:generate manually it does generate xsd classes in generate-source folder but does not pack in war.

How can i make it generate xsd classes without manually executing "mvn jaxb2:generate" and make it part of the war ? thanks i Advance.

<plugin>
          <groupId>org.jvnet.jaxb2.maven2</groupId>
          <artifactId>maven-jaxb2-plugin</artifactId>
          <version>0.8.3</version>
          <executions>
            <execution>
              <phase>generate-sources</phase>
              <goals>
                <goal>generate</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <schemaDirectory>src/main/wsdl</schemaDirectory>
          </configuration>
        </plugin>

Upvotes: 0

Views: 2198

Answers (2)

Lavanya
Lavanya

Reputation: 319

It will not generate the XSD classes when you run mvn clean compile package, as generate-sources is not part of the packaging goal. The default bindings for WAR packaging would be process-resources compile process-test-resources test-compile
test package install deploy

You can wrap it around a profile, and run the mvn build with that profile The other reason being to use profile is you can use this profile only whenever you need to generate the java classes, othertimes you can just run the regular build.

The format is

<profiles>
   <profile>
     <id>generateFromSchemas</id>
        <plugin>
           ......
        </plugin>
   </profile>
 <profiles>

mvn -P generateFromSchemas

Upvotes: 1

d-man
d-man

Reputation: 58103

I slightly updated my plugin as following

<plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.8.3</version>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <generatePackage>com.equilibriums.samplespringws</generatePackage>
        <schemaDirectory>src/main/wsdl</schemaDirectory>
      </configuration>
    </plugin>

and following is the maven command

mvn jaxb2:generate compile package

and it worked awesome.

Upvotes: 0

Related Questions