简体   繁体   中英

Bundling generated classes into a jar and adding it to the build class-path

I am working in Java maven environment, in my application I am generating some java classes using a SomeFileName.wsdl file. For this I have added maven plugin to pom.xml, following are the plugins,

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/folder-name</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>some-id</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <wsdlDirectory>src/main/webapp/WEB-INF/wsdl</folder-name>
                            <wsdlFiles>
                                <wsdlFile>SomeFileName.wsdl</wsdlFile>
                            </wsdlFiles>
                            <wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

My question around this is, whenever this plugin generates java classes under target/generated-sources/folder-name , is there any maven plugin or maven goal or some other way available so that I can bundle this classes into a jar and can be able to add that jar to my class-path(build-path). So that, I can be able to access those generated classes from newly generated jar.

In simple words, currently using wsdl plugin classes are getting generated into target folder where I have specified my location. I just want to bundle those generated classes into a jar and add that jar to a buildpath, is there anyway to achieve this?

I have used jax-ws in some maven projects, and the class files from the generated stubs will simply be generated in the target folder, just like other class files. The generated sources config only affects the generated sources. The .class files will end up in your package structure. My suggestion is to add the packageName config, so your generated classes will be in a more convenient package. Once you build your project and the wsdl is imported successfully, you should see your .class files in the targer folder. After that, the jar packaging will go as any other project. Here is an example configuration (very similar to yours):

            <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>1.12</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <packageName>com.your.package</packageName>
                        <sourceDestDir>target/generated-sources/jaxws</sourceDestDir>
                        <verbose>true</verbose>
                    </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