【发布时间】: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 安装