简体   繁体   English

将生成的类捆绑到jar中,并将其添加到构建类路径中

[英]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. 我在Java Maven环境中工作,在我的应用程序中,我使用SomeFileName.wsdl文件生成一些Java类。 For this I have added maven plugin to pom.xml, following are the plugins, 为此,我将maven插件添加到pom.xml,以下是这些插件,

        <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). 我对此的疑问是,每当此插件在target/generated-sources/folder-name下生成java类时,是否有任何maven插件或maven目标或其他可用方式,以便我可以将此类捆绑到jar中并能够将该jar添加到我的class-path(build-path)中。 So that, I can be able to access those generated classes from newly generated jar. 这样,我就能从新生成的jar中访问那些生成的类。

In simple words, currently using wsdl plugin classes are getting generated into target folder where I have specified my location. 简而言之,当前使用wsdl插件的类将生成到我指定位置的目标文件夹中。 I just want to bundle those generated classes into a jar and add that jar to a buildpath, is there anyway to achieve this? 我只想将这些生成的类捆绑到jar中,然后将该jar添加到buildpath中,是否有实现此目标的方法?

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. 我已经在一些Maven项目中使用了jax-ws,并且与其他类文件一样,将仅在目标文件夹中生成来自生成的存根的类文件。 The generated sources config only affects the generated sources. 生成的源配置仅影响生成的源。 The .class files will end up in your package structure. .class文件将最终出现在您的程序包结构中。 My suggestion is to add the packageName config, so your generated classes will be in a more convenient package. 我的建议是添加packageName配置,这样生成的类将放在更方便的包中。 Once you build your project and the wsdl is imported successfully, you should see your .class files in the targer folder. 构建项目并成功导入wsdl后,您应该在targer文件夹中看到.class文件。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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