0

我可以通过运行 Grails 命令 'war' 来构建一个 war 文件,并且该 war 文件可以完美运行。

说到maven,它根本不起作用!我通过运行'clean package'构建项目,并跳过了所有测试(不知道这是否会影响战争)

战争文件是在目标目录中生成的,但我注意到战争文件的大小与 grails 命令生成的不同。此外,当我将 maven 生成的 war 文件部署到 out tomcat 服务器上时,它无法运行。

另一个问题是我需要在 pom.xml 中添加 maven-war 吗?因为如果我不添加目标,它仍然会构建一个war文件,与设置目标有什么区别?

我的 pom 文件:

<properties>
    <grails.version>2.1.1</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-test</artifactId>
        <version>${grails.version}</version>
        <scope>compile</scope>
    </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>
        <scope>provided</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>cache</artifactId>
        <version>1.0.1</version>
        <scope>compile</scope>
        <type>zip</type>
    </dependency>
   <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>database-migration</artifactId>
        <version>1.3.2</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>
      <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>joda-time</artifactId>
        <version>1.4</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency> 
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>hibernate</artifactId>
        <version>${grails.version}</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>jquery-ui</artifactId>
        <version>1.8.24</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>jquery</artifactId>
        <version>1.8.0</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>resources</artifactId>
        <version>1.1.6</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>webxml</artifactId>
        <version>1.4.1</version>
        <scope>provided</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>1.2.7.3</version>
        <scope>provided</scope>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>1.0.6</version>
        <scope>provided</scope>
        <type>zip</type>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>com.rbccm.erebus</groupId>-->
        <!--<artifactId>erebus</artifactId>-->
        <!--<version>4.1.1-SNAPSHOT</version>-->
    <!--</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>
                    <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>
                <!-- Whether for Fork a JVM to run Grails commands -->
                 <skipTests>true</skipTests>
                <fork>true</fork>
            </configuration>
            <extensions>true</extensions>
            <executions>
            <execution>
                <goals>
                    <goal>clean</goal>
                    <goal>maven-war</goal>
                </goals>
            </execution>
        </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                 <!-- fix for grails bug http://jira.grails.org/browse/MAVEN-1 -->
                    <id>recopy-resources-after-grails</id>
                    <phase>package</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </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>
</repositories>
<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>

4

1 回答 1

0

我发现我错过了一个jar依赖,所以war文件无法运行

于 2013-02-19T11:57:14.847 回答