【问题标题】:How to remove tomcat plugin from Maven如何从 Maven 中删除 tomcat 插件
【发布时间】:2016-01-02 08:25:47
【问题描述】:

我有一个 maven 项目,它与 tomcat 7 插件合并。每当我做 maven:install 它在 war 文件中生成并将其放置在 tomcat web apps 文件夹中,我可以使用 localhost:8080 访问

现在想把tomcat7换成tomcat 8,也想单独运行tomcat。

现在我正在使用 Tomcat7 插件和 maven,我不想将 Tomcat 7 与 maven 一起使用,我想使用我系统中的 Tomcat 8。

怎么做?

对于我的新 tomcat 服务器,是否可以告诉 maven 将生成的 war 文件放置到新的 tomcat 服务器 webapps 文件夹中。

请在下面找到我的 pom.xml 以进行 tomcat 插件配置

   <!-- Used by embedded Tomcat to move context.xml for JNDI resources -->
            <!-- Configuration inherited from parent -->            
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
            <!-- Main configuration inherited from parent -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <path>/</path>
                    <port>${httpPort}</port>
                    <httpsPort>${httpsPort}</httpsPort>
                </configuration>
            </plugin>

下面是我的 ant 脚本,它有助于在嵌入式 tomcat 中部署 war 文件

<target name="tomcat" >
        <delete dir="war/WEB-INF/lib"/>
        <artifact:mvn mavenHome="${maven.home}" fork="true">
            <jvmarg value="-XX:MaxPermSize=256M" />
            <jvmarg value="-Xmx512M" />
            <jvmarg value="-Xdebug" />
            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" />
            <jvmarg value="-javaagent:${spring.instrument.path}" />
            <jvmarg value="-Druntime.environment=${runtime.environment}" />
            <jvmarg value="-Ddatabase.user=${database.user}" />  
            <jvmarg value="-Ddatabase.password=${database.password}" />  
            <jvmarg value="-Ddatabase.driver=${database.driver}" />  
            <jvmarg value="-Ddatabase.url=${database.url}" />  
            <arg value="compile"/>
            <arg value="war:exploded"/>
            <arg value="tomcat7:run"/>
        </artifact:mvn>
    </target>

还有我的父 Pom.xml

            <!-- Moves the context.xml file into a location that embedded Tomcat can read from -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/${tomcat.conf.dir.name}</outputDirectory>
                            <resources>
                                <resource>


    <directory>${project.basedir}/../lib/${tomcat.conf.dir.name}</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Main coniguration for embedded Tomcat -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
<!--                         Useful when deploying to Tomcat elsewhere on the system -->
                        <update>true</update>
                        <url>http://127.0.0.1:8080/manager/text</url>
                        <username>tomcatscript</username>
                        <password>secret</password>


    <additionalConfigFilesDir>${project.build.directory}/${tomcat.conf.dir.name}</additionalConfigFilesDir>
<!--                         See the configuration in the keytool-maven-plugin -->
                        <keystorePass>broadleaf</keystorePass>
                        <keystoreFile>${webappDirectory}/WEB-INF/blc-example.keystore</keystoreFile>

<!--                         System properties for JNDI data sources (database.url, database.driver etc) are passed in via -->
<!--                             build.xml as -D arguments -->

                    </configuration>
                    <dependencies>
<!--                         Other dependencies -->

                        <dependency>
                            <groupId>commons-dbcp</groupId>
                            <artifactId>commons-dbcp</artifactId>
                            <version>1.4</version>
                            <type>jar</type>
                            <scope>compile</scope>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.tomcat</groupId>
                            <artifactId>tomcat-jdbc</artifactId>
                            <version>7.0.30</version>
                            <type>jar</type>
                            <scope>compile</scope>
                        </dependency>
                    </dependencies>
                </plugin>

现在如何更改我的 pom.xml 或 ant 脚本以删除嵌入式 tomcat 并包含本地 tomcat 当我运行我的 ant 脚本时,Maven 应该能够将其部署或重新部署到本地 tomcat 安装。

谢谢

【问题讨论】:

  • 嗯,有一个tomcat8插件......但是当你说你“想单独保留tomcat”时,你真的不清楚你想要什么。
  • 您应该编辑您的问题以包含 pom.xml 文件的相关部分。
  • @Rob 很快就会为您提供 ..
  • @dcsohl 我不想使用 tomcat 7 作为 maven 的插件,我想在我的系统中使用 tomcat 安装

标签: java eclipse maven tomcat


【解决方案1】:

首先需要去掉启动Tomcat7的tomcat7-maven-plugin相关配置。

其次,您可以将 tomcat7-maven-plugin 配置为使用 Tomcat X REST 管理 API,并按照 http://www.disasterarea.co.uk/blog/deploying-to-tomcat-7-with-maven/ 所述使用 maven 将您的战争部署到它

【讨论】:

  • 该链接解释了如何使用嵌入式 tomcat maven 插件。我想用 maven 删除 tomcat 插件并添加 tomcat 本地安装
  • 不,该链接说明了如何使用 tomcat-maven-plugin 部署到本地 Tomcat 安装。为此,您只需指定配置选项:urlusernamepassword。然后,你运行mvn tomcat7:deploy
  • 请注意,当您使用tomcat7-maven-plugin 时,您并不总是使用嵌入式 Tomcat7。仅当您使用目标 run 或其他一些时,您才使用嵌入式。目标deployundeployredeploy 不要使用嵌入式目标。尽管如此,tomcat7-maven-plugin 确实依赖于嵌入式,因此它将被下载到您的 maven 本地 repo。但是,如果您执行我上面列出的目标,则不会使用它。
  • 你能在你的回答中更简单地解释一下吗..谢谢!!
猜你喜欢
  • 1970-01-01
  • 2011-06-23
  • 2019-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
相关资源
最近更新 更多