Search code examples
javaweb-servicesmavensoapwsdl

Maven clean - delete target folder what leads to unresolved imports


I am generating classes from WSDL using maven apache.cxf plugin. It will generate classes to "target" folder.

I am using these classes in my project (import generated.wsdlclass...) but when I run mvn clean install it will delete target folder completely which leads to unresolved imports in my project and maven will crash regenerating target folder. It complains I have errors in my project (because it deletes my generated classes I was using)...

How should I solve this problem ? At first of all I thought maybe I should tell maven don't delete my generated classes in my target folder but I've read it's against maven policy and it is not good practice to do it. What's the best approach to solve this problem ? How should I generate classes from wsdl and how should I use them ?

Thanks


Solution

  • The classes must be generated before the compile phase. To achieve that bind the maven-plugin to the generate-sources phase.

    <plugin>
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <version>...</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>...</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    See also the Maven Lifecycle Reference.