首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Grails中,命令“tomcat:部署”不像命令"dev war“那样生成完整的war。

在Grails中,命令“tomcat:部署”不像命令"dev war“那样生成完整的war。
EN

Stack Overflow用户
提问于 2013-05-23 03:35:38
回答 2查看 1.1K关注 0票数 0

命令"grails war“使用生成的包含下一个文件夹的war在本地Tomcat6服务器中完美地部署

代码语言:javascript
复制
css
images
js
META-INF
plugins
WEB-INF

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
META-INF
WEB-INF

为了能够使用"tomcat部署“,我将下一段代码添加到pom.xml中(在添加pom true之后,运行”create组“和其他配置更改):

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-23 19:10:41

它很好地解决了这一问题:

配置

以前,如果您在插件m2e中使用Eclipse,下面将介绍如何配置Eclipse以便在其中使用Tomcat:tomcat-maven-plugin: Server returned HTTP response code: 403

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

代码语言:javascript
复制
<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=development grails:war
  • tomcat:重新部署-Dgrails.env=development -DskipTests

Note1:如果我们不添加-DskipTests (在部署之前没有运行测试),并且一些测试失败了,那么它就不会部署。

Note2:在eclipse中(安装了用于maven的插件m2e ),您必须在下一个字段中键入以下命令:

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

更新1

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

更新2

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

票数 1
EN

Stack Overflow用户

发布于 2013-05-23 04:23:44

试一试

代码语言:javascript
复制
mvn grails:war tomcat:redeploy -DskipTests

希望这样可以让grails将正确的WAR伪制品附加到构建中,这样就不会上传空的默认版本了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16705243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档