Maven版本的差异:使用jython时准备和安装jar

时间:2012-07-24 03:14:11

标签: maven jython maven-release-plugin

我正在使用Maven 3.0.4以及Jython 2.5.2和Pygments 1.5(通过一个鸡蛋)。我已将jython-compile-maven-plugin配置为

<plugin>
<groupId>net.sf.mavenjython</groupId>
<artifactId>jython-compile-maven-plugin</artifactId>
<version>1.2</version>
<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>jython</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <libraries>
        <!-- Install the latest pygments library -->
        <param>Pygments</param>
    </libraries>
</configuration>

运行 mvn install 创建的JAR包含嵌入在 Lib 文件夹中的 Pygments 库。这可以确保我的所有代码都能正常运行。

当我运行 mvn release:prepare 命令时,问题就出现了。在这种情况下,只有我的代码进入JAR,并且 Pygments 库被遗漏了。如果我查看 target / classes 文件夹,它包含我的代码和所需的pygments库。

关于我可能遗失或做错的任何想法?

1 个答案:

答案 0 :(得分:0)

经过大量的点击和试运行后,我能够自行解决问题。该解决方案使用配置 maven-jar-plugin 来包含目标/类文件夹中的所有文件。这样,安装版本:准备目标都会构建完全相同的二进制文件。

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
    <includes>
        <include>**</include>
    </includes>
</configuration>
<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>jar</goal>
        </goals>
    </execution>
</executions>
</plugin>

我用于项目的整个构建条目如下:

<build>
<plugins>
    <!-- set compilation properties -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>

    <!-- Generate the project-javadoc.jar for OSS repository -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.8.1</version>
    </plugin>

    <!-- Generate the project-sources.jar for OSS repository -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.1.2</version>
    </plugin>

    <!-- Install Jython and Pygments library -->
    <plugin>
        <groupId>net.sf.mavenjython</groupId>
        <artifactId>jython-compile-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>jython</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <libraries>
                <!-- Install the latest pygments library -->
                <param>Pygments</param>
            </libraries>
        </configuration>
    </plugin>       

    <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <includes>
                <include>**</include>
            </includes>
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
</build>

希望这有帮助。