0

I am developing grails app using maven.

While running command "mvn package" it generates the war with version no. But I want to generate war without version no and also want to exclude some jars. Here is my pom.xml

 <?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.brickred</groupId>
    <artifactId>my-grails-demo</artifactId>
    <packaging>grails-app</packaging>
    <version>1.0</version>

    <name>A custom grails project</name>
    <description>A custom grails project</description>
    <url>http://www.myorganization.org</url>

    <properties>
        <grails.version>2.2.2</grails.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.grails</groupId>
            <artifactId>grails-dependencies</artifactId>
            <version>${grails.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.grails</groupId>
            <artifactId>grails-plugin-testing</artifactId>
            <version>${grails.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>tomcat</artifactId>
            <version>${grails.version}</version>
            <type>zip</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>hibernate</artifactId>
            <version>${grails.version}</version>
            <type>zip</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>jquery</artifactId>
            <version>1.8.3</version>
            <type>zip</type>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>cache</artifactId>
            <version>1.0.1</version>
            <type>zip</type>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>resources</artifactId>
            <version>1.1.6</version>
            <type>zip</type>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>database-migration</artifactId>
            <version>1.3.2</version>
            <type>zip</type>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>cache</artifactId>
            <version>1.0.1</version>
            <type>zip</type>
            <scope>runtime</scope>
        </dependency>





    </dependencies>

    <build>
        <pluginManagement />

        <plugins>
            <!-- Disables the Maven surefire plugin for Grails applications, as we 
                have our own test runner -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>surefire-it</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>plugins</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.grails</groupId>
                <artifactId>grails-maven-plugin</artifactId>
                <version>${grails.version}</version>
                <configuration>
                    <fork></fork>
                </configuration>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1-beta-1</version>
                <configuration>
                    <warName>socialauth-grails-demo</warName>
                    <packagingExcludes> %regex[WEB-INF/lib/.*(?:servlet).*.jar]</packagingExcludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>grails</id>
            <name>grails</name>
            <url>http://repo.grails.org/grails/core</url>
        </repository>
        <repository>
            <id>grails-plugins</id>
            <name>grails-plugins</name>
            <url>http://repo.grails.org/grails/plugins</url>
        </repository>

        <!-- uncomment the following snapshot repository if you want to use snapshot 
            versions of the grails-maven-plugin -->
        <!-- <repository> <id>grails-plugins-snapshots</id> <name>grails-maven-plugins</name> 
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url> <snapshots> 
            <enabled>true</enabled> </snapshots> </repository> -->
    </repositories>

    <!-- uncomment the following snapshot repository if you want to use snapshot 
        versions of the grails-maven-plugin -->
    <!-- <pluginRepositories> <pluginRepository> <id>grails-maven-plugins</id> 
        <name>grails-maven-plugins</name> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> 
        <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> -->

    <profiles>
        <profile>
            <id>tools</id>
            <activation>
                <property>
                    <name>java.vendor</name>
                    <value>Sun Microsystems Inc.</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>${java.version}</version>
                    <scope>system</scope>
                    <systemPath>${java.home}/../lib/tools.jar</systemPath>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>


mvn package generates the war my-grails-demo-1.0.war. I need to generate without version and also want to excludes servlet.jar

4

3 回答 3

1

您应该能够在您的依赖项中使用提供的范围排除传递依赖项的 jar。

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0</version>
    <scope>provided</scope>
</dependency>

但是要在 war 插件中明确排除 jar,您可以使用packagingExcludes,它看起来就像您拥有的一样。正则表达式是否可能存在问题,您是否尝试过简单地传递PackagingExcludes jar 的逗号列表。

至于版本号(这是必需的),您可以更改生成的战争的名称,如构建部分中的 finalName 属性

<build>
  ...
  <finalName>your final war name</finalName>
于 2013-05-30T16:08:51.493 回答
1

您可以执行以下任一操作:

  • 如果您使用mvn package,则在中设置以下设置Config.groovy
    grails.project.war.file = "target/${yourDesiredName}.war"

  • 您也可以使用打包mvn grails:war yourWarName.war

为了在战争中排除 jar,请在下面使用BuildConfig.groovy

grails.war.resources = { stagingDir ->
    delete(file:"${stagingDir}/WEB-INF/lib/servlet.jar")
}

一条建议:- 使用mvn install而不是mvn package

于 2013-05-30T16:10:44.187 回答
0

我在 BuildConfig.groovy 文件中创建以下条目以从 lib 文件夹中删除 jar。

grails.war.resources = { stagingDir ->
    new File("${stagingDir}/WEB-INF/lib").eachFileMatch(~/.*(servlet).*.jar/)  {
        f -> f.delete()
    }

}

我必须使用正则表达式,因为 lib 文件夹中出现了不同版本的 servlet.jar。

于 2013-05-31T21:44:46.610 回答