我正在使用maven开发grails app。
在运行命令“mvn package”时,它会生成版本为no的war。但我想生成没有版本号的战争,也想排除一些罐子。这是我的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 生成war my-grails-demo-1.0.war。我需要生成没有版本,也想要排除servlet.jar
答案 0 :(得分:1)
您应该能够在依赖项中使用提供的范围排除具有传递依赖性的jar。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
但是要在war插件中明确排除jar,您可以使用 packagingExcludes ,它看起来像你一样。是否有可能是正则表达式存在问题,您是否尝试过简单地传递 packagingExcludes 一个罐子的逗号列表。
对于版本号(需要),您可以更改生成的war的名称,例如构建部分中的finalName属性
<build>
...
<finalName>your final war name</finalName>
答案 1 :(得分: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
答案 2 :(得分:0)
我在BuildConfig.groovy文件中输入以下条目以从lib文件夹中删除jar。
grails.war.resources = { stagingDir ->
new File("${stagingDir}/WEB-INF/lib").eachFileMatch(~/.*(servlet).*.jar/) {
f -> f.delete()
}
}
我必须使用正则表达式,因为在lib文件夹中出现了不同版本的servlet.jar。