如何自动将xmlbeans生成的java源包含到maven jar中?

时间:2016-04-18 06:45:20

标签: java xml maven resources xmlbeans

我正在使用xmlbeans-maven-plugin从xsds生成源代码。一世 使用已编译的类成功生成jar文件。但 不幸的是我不能将java源(.java)文件包含到maven中 生成的jar文件。当我想使用maven-resources-plugin或 maven-sources-plugin它使用.java源创建一个jar文件 在jar文件的末尾添加了后缀(-resources或-sources)。

我不想使用任何其他插件。我只想用 使用xmlbeans创建java创建我的jar文件的xmlbeans-maven-plugin 源。

我的pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Properties Definitions -->
<properties>
    <project.name>myxmlbeansproject</project.name>
    <project.version>5.0.6</project.version>
    <project.packaging>jar</project.packaging>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.sources.directory>src/main/resources/xsds</project.sources.directory>
    <project.java.version>1.4</project.java.version>
</properties>
<!-- End 0f Properties Definitions -->

<!-- Project Defaults Definitions -->  
<modelVersion>4.0.0</modelVersion>
<groupId>my.xmlbeans</groupId>
<artifactId>my.xmlbeans.project.artifact</artifactId>
<packaging>jar</packaging>
<version>${project.version}</version>
<name>myxmlbeansproject</name>
<description>TMGW Schema Project</description>
<!-- End of Project Defaults Definitions -->

<!-- Dependencies -->
<dependencies>
    <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>2.4.0</version>
        <scope>compile</scope>
    </dependency>
</dependencies>
<!-- End of Dependencies -->

<!-- Build Definitions & xmlbean Plugin Definition -->
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xmlbeans-maven-plugin</artifactId>
            <version>2.3.3</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xmlbeans</goal>
                    </goals>
                </execution>
            </executions>
        <configuration>
            <schemaDirectory>${project.sources.directory}/${project.version}</schemaDirectory>
            <javaSource>${project.java.version}</javaSource>
            <sourceGenerationDirectory>javasources/</sourceGenerationDirectory>
            <staleFile>stalefile/xsd.stale</staleFile>
            <outputJar>${project.name}-${project.version}.${project.packaging}</outputJar>
            <detail>true</detail>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <executions>
            <execution>
                <id>copy-resources</id>
                <phase>validate</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>/javasources</outputDirectory>
                    <resources>
                        <resource>
                            <directory>javasources/</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>attach-sources</id>
                <goals>
                    <goal>jar-no-fork</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <finalName>${project.name}-${project.version}.${project.packaging}</finalName>
            <attach>true</attach>
        </configuration>
        </plugin>
    </plugins>
</build>
<!-- End of Build Definitions & xmlbean Plugin Definition -->

<!-- Nexus Repository & Distribution Management Definitions -->
<repositories>
    <repository>
        <id>RepoNexus</id>
        <url>${REPO_SERVER}content/repositories/public/</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>RepoNexusPluginRep</id>
        <url>${REPO_SERVER}content/repositories/public</url>
    </pluginRepository>
</pluginRepositories>
<distributionManagement>
    <snapshotRepository>
        <id>nexus.snapshots</id>
        <name>nexus.snapshots</name>
        <url>${REPO_SERVER}content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
        <id>nexus.releases</id>
        <name>nexus.releases</name>
        <url>${REPO_SERVER}content/repositories/releases</url>
    </repository>
</distributionManagement>
<!-- End of Nexus Repository & Distribution Management finitions -->

0 个答案:

没有答案