Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails-maven使用版本号构建战争_Grails_Grails Maven - Fatal编程技术网

Grails-maven使用版本号构建战争

Grails-maven使用版本号构建战争,grails,grails-maven,Grails,Grails Maven,我正在使用maven开发grails应用程序 在运行命令“mvn package”时,它会生成版本号为的war。但是我想生成没有版本号的war,还想排除一些JAR。这是我的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"

我正在使用maven开发grails应用程序

在运行命令“mvn package”时,它会生成版本号为的war。但是我想生成没有版本号的war,还想排除一些JAR。这是我的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>

4.0.0
org.brickred
我的圣杯演示
grails应用程序
1
自定义grails项目
自定义grails项目
http://www.myorganization.org
2.2.2
org.grails
grails依赖项
${grails.version}
聚甲醛
org.grails
grails插件测试
${grails.version}
测试
org.grails.plugins
雄猫
${grails.version}
拉链
假如
org.grails.plugins
冬眠
${grails.version}
拉链
编译
org.grails.plugins
jquery
1.8.3
拉链
运行时
org.grails.plugins
隐藏物
1.0.1
拉链
运行时
org.grails.plugins
资源
1.1.6
拉链
运行时
org.grails.plugins
数据库迁移
1.3.2
拉链
运行时
org.grails.plugins
隐藏物
1.0.1
拉链
运行时
org.apache.maven.plugins
maven surefire插件
真的
当然可以
集成测试
测试
假的
org.apache.maven.plugins
maven清洁插件
2.4.1
插件
**/*
假的
org.grails
GrailsMaven插件
${grails.version}
真的
org.apache.maven.plugins
maven编译器插件
1.6
1.6
org.apache.maven.plugins
maven战争插件
2.1-β-1
socialauth grails演示
%regex[WEB-INF/lib/*(?:servlet.*.jar]
圣杯
圣杯
http://repo.grails.org/grails/core
grails插件
grails插件
http://repo.grails.org/grails/plugins
工具
java.vendor
太阳微系统公司。
com.sun
工具
${java.version}
系统
${java.home}/./lib/tools.jar


mvn包生成war my-grails-demo-1.0.war。我需要不使用版本生成,还想排除servlet.jar

您应该能够排除依赖项中提供的范围为的可传递依赖项的jar

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

javax.servlet
servlet api
3
假如
但是要在war插件中显式排除jar,可以使用看起来像您已经拥有的packagingExcludes。正则表达式是否可能有问题,您是否尝试过简化传递packagingExcludesjar的逗号列表

至于版本号(这是必需的),您可以使用build部分中的finalName属性更改生成的war-like的名称

<build>
  ...
  <finalName>your final war name</finalName>

...
你最后的战名

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

  • 如果使用
    mvn软件包
    ,则在
    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安装
而不是
mvn包

我在BuildConfig.groovy文件中输入以下内容,以从lib文件夹中删除jar。

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

}

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

提供的
范围不排除jar。它用于依赖关系管理。当作用域被提供时,依赖关系由JDK/容器在运行时提供。有关详细信息,请参阅。@dmahapatro-从技术上讲,如果JAR是可传递依赖项,则“提供”将排除JAR,这种情况经常发生。但是你是对的,仅仅“提供的”作用域并不能明确地排除jar——我的反应有点过火了。我将更新答案。我的观点是,
提供的
用于其他用途,而不是排除JAR的选项。而且,你会