0

命令“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

我添加了一个空的 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>
4

2 回答 2

1

这是完美的工作:

配置

以前,如果您使用带有插件 m2e 的 Eclipse,这里解释了如何配置 Eclipse 以使用 Tomcat: tomcat-maven-plugin:服务器返回 HTTP 响应代码: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:重新部署-DskipTests

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

  • grails:war tomcat:redeploy -Dgrails.env=开发 grails:war
  • tomcat:重新部署 -Dgrails.env=development -DskipTests

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

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

  • 运行 - 运行配置 - 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

于 2013-05-23T19:10:41.463 回答
0

尝试

mvn grails:war tomcat:redeploy -DskipTests

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

于 2013-05-23T04:23:44.333 回答