【问题标题】:In Grails, the command "tomcat:deploy" does not generate the complete war as the command "dev war" does在 Grails 中,命令“tomcat:deploy”不会像命令“dev war”那样生成完整的战争
【发布时间】:2013-05-18 07:12:27
【问题描述】:

命令“grails dev war”完美部署在我的本地Tomcat6服务器中,生成的war包含下一个文件夹:

css
images
js
META-INF
plugins
WEB-INF

不幸的是,我需要命令 tomcat:deploy 也可以工作(我实际上正在使用:tomcat:redeploy -DskipTests)。但是 Tomcat 给出了下一个错误

2013-05-23 05:12:53,094 [http-8080-4] ERROR digester.Digester  - Parse Fatal Error at line 1 column 1: Final de archivo prematuro.
org.xml.sax.SAXParseException; systemId: jndi:/localhost/Alojamiento/WEB-INF/web.xml; lineNumber: 1; columnNumber: 1; Final de archivo prematuro.
    at

我添加了一个 empty web.xml 以便 maven 编译。在生成的战争中它也是空的。所以这可能是问题的原因(“grails dev war”生成带有代码的 web.xml)。此外,生成的战争只包含下一个文件夹:

META-INF
WEB-INF

为了能够使用“tomcat deploy”,我在 pom.xml 中添加了下一个代码(添加 pom true 后,运行“create-pom group”和其他配置更改):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
        <url>http://127.0.0.1:8080/manager</url>                    
        <server>TomcatServer</server>
    </configuration>
</plugin>

更新 1 我的完整 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>alojamiento.ingenierosIW</groupId>
    <artifactId>Alojamiento</artifactId>
    <packaging>war</packaging>
    <version>0.1</version>
    <name>Alojamiento</name>
    <description>Alojamiento</description>

    <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-test</artifactId>
            <version>${grails.version}</version>
            <scope>test</scope>
        </dependency>

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


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.25</version>
        <scope>runtime</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>spring-security-core</artifactId>
        <version>1.2.7.3</version>
        <scope>compile</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>resources</artifactId>
        <version>1.2.RC2</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>


    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>db-reverse-engineer</artifactId>
        <version>0.5</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>


    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>jquery</artifactId>
        <version>1.8.3</version>
        <scope>runtime</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>hibernate</artifactId>
        <version>2.2.2</version>
        <scope>runtime</scope>
        <type>zip</type>
    </dependency>


    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>tomcat</artifactId>
        <version>2.2.2</version>
        <scope>provided</scope>
        <type>zip</type>
    </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>
                    <!-- Whether for Fork a JVM to run Grails commands -->
                    <fork>true</fork>
                </configuration>
                <extensions>true</extensions>
            </plugin>


             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <!--<ignorePackaging>true</ignorePackaging>-->
                    <addContextWarDependencies>true</addContextWarDependencies>
                    <url>http://127.0.0.1:8080/manager</url>                    
                    <server>TomcatServer</server>
                    <!--<username>admin</username>-->
                    <!-- <password>password</password>-->
                    <!-- <path>/u74937912-practica-WAR</path>-->
                </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>
    </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>
</project>

【问题讨论】:

  • 你能发布完整的 pom 吗?听起来 maven 的 tomcat 插件使用的是 maven 生成的 WAR 工件,而不是 grails 插件生成的(我假设你已经在 pom 中配置了?)
  • 我用 pom.xml 更新了它(更新 1)。我该如何配置它?我实际上试图在谷歌中找到但没有运气

标签: maven grails grails-plugin sts-springsourcetoolsuite


【解决方案1】:

它完美地处理了这个:

配置

之前,如果您使用带有插件 m2e 的 Eclipse,这里解释了如何配置 Eclipse 以使用 Tomcat: tomcat-maven-plugin: Server returned HTTP response code: 403

现在,我们需要在 C:\Users\user.m2 中使用与 tomcat-users.xml 相同的用户名和密码的正确 settings.xml。然后,我们需要将我们的 pom.xml 配置如下:

<packaging>war</packaging>


<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
    <url>http://127.0.0.1:8080/manager</url>   
    <!-- The next server must be the same than the one in settings.xml (at C:\Users\user\.m2): -->
    <server>TomcatServer</server>
</configuration>
</plugin>   


<plugin>
    <groupId>org.grails</groupId>
    <artifactId>grails-maven-plugin</artifactId>
    <version>${grails.version}</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <goals>
                <goal>init</goal>
                <goal>maven-clean</goal>
                <goal>validate</goal>
                <goal>config-directories</goal>
                <goal>maven-compile</goal>
                <goal>maven-test</goal>
                <goal>maven-war</goal>
                <goal>maven-functional-test</goal>
            </goals>
        </execution>
        </executions>
</plugin>

要部署的 MAVEN 命令:

下一条命令从 datasource.groovy 获取我们数据库的配置值 - 生产环境:

  • tomcat:重新部署
  • tomcat:重新部署-DskipTests
  • grails:war tomcat:redeploy -DskipTests

要从开发环境中获取值,命令如下:

  • grails:war tomcat:redeploy -Dgrails.env=development grails:war
  • tomcat:redeploy -Dgrails.env=development -DskipTests

注意1:如果我们不添加-DskipTests(部署之前没有运行测试),并且某些测试失败,它将不会部署。

注意2:在eclipse中(安装了maven的插件m2e),你必须在下一个字段中输入这些命令:

  • 运行 - 运行配置 - Maven 构建 - 目标

更新 1

不要忘记在src/main/webapp/WEB-INF下创建一个空的web.xml!

更新 2

不要忘记告诉 Grails 使用 pom.xml:http://grails.org/doc/2.3.x/ref/Command%20Line/create-pom.html

【讨论】:

  • 我认为关键部分是将 Grails 插件绑定到 maven-war 阶段。您应该接受自己的答案,因为它是 grails 插件正确配置的一个很好的参考。
  • 当然!但我必须等待 17 小时;)
【解决方案2】:

试试

mvn grails:war tomcat:redeploy -DskipTests

这应该有望让 grails 将正确的 WAR 工件附加到构建中,这样就不会上传空的默认值。

【讨论】:

  • 谢谢,但不幸的是同样的错误发生了,生成的战争看起来一样。
  • 也许我必须手动配置 tomcat-maven-plugin 以包含战争中的所有内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-01
  • 2013-04-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多