简体   繁体   English

Netbeans使用Maven为Tomcat5和Tomcat7构建Web应用程序

[英]Netbeans to build a webapp for Tomcat5 and Tomcat7 using Maven

I have a project that contains a number of webapps and jsps and builds fine as a .war file. 我有一个包含许多webapp和jsps的项目,并且可以很好地构建为.war文件。

I now need to persuade Netbeans and Maven to build both a Tomcat-7 version and a Tomcat-5 version. 我现在需要说服Netbeans和Maven同时构建Tomcat-7版本和Tomcat-5版本。 Could someone point me in the right direction? 有人可以指出我正确的方向吗?

I would also like to be able to include a different web.xml depending on which customer I am building for but I suspet I may be able to get that to happen myself once the above is answered. 我也希望能够包含一个不同的web.xml,这取决于我要为哪个客户构建,但是我怀疑一旦上述问题得到解决,我也许可以自己实现。

I guess I need to use two profiles in my pom file but I have no idea what I need to put in each one to select: 我想我需要在pom文件中使用两个配置文件,但是我不知道需要在每个配置文件中进行选择:

a) The correct jdk to compile with (JDK 6 for TC-7 and JDK 5 for TC-5)
b) The correct version of the javax libraries.

I am using Netbeans 7.1.2. 我正在使用Netbeans 7.1.2。

The optimal result would be having one war file that will work on both Tomcat 5 and Tomcat 7 and is the same for every customer. 最佳结果是拥有一个可以同时在Tomcat 5和Tomcat 7上使用并且对每个客户都相同的war文件。

You can use maven profiles to adopt the build for every customer but I recommend to externalize the individual config into JNDI or an external properties file read via some environment variable. 您可以使用Maven概要文件为每个客户采用构建,但是我建议将单个配置外部化为JNDI或通过某些环境变量读取的外部属性文件。 Spring offers the PropertyResolverconfigurer to do that (for example) Spring提供了PropertyResolverconfigurer来做到这一点(例如)

Since you want to support Tomcat 5 I guess your project builds with Java 1.5? 因为您想支持Tomcat 5,所以我猜您的项目是使用Java 1.5构建的吗? That should run on Tomcat 7 as well. 那也应该在Tomcat 7上运行。

The javax dependencies should have scope provided in your pom.xml files. javax依赖项应在pom.xml文件中提供范围。 So they will not be deployed. 因此它们将不会被部署。 If your application requires a specific version of a jar that is part of tomcat already you may be able to solve that with profiles as well. 如果您的应用程序需要特定版本的jar,而该版本是tomcat的一部分,那么您也可以使用配置文件解决该问题。 But this may conflict with per-customer profiles. 但这可能与每个客户的个人资料冲突。

If there a big differences between your Tomcat 5 and Tomcat 7 version it may be an idea to create 3 modules - all using packaging "war". 如果您的Tomcat 5和Tomcat 7版本之间有很大差异,则可能会创建3个模块-全部使用打包的“ war”模块。 One containing the 'neutral' files, one containing the tomcat 5 files and one the tomcat 7 files. 一个包含“中性”文件,一个包含tomcat 5文件,另一个包含tomcat 7文件。 The tomcat projects would use the neutral module as war file dependency and maven will do a war overlay. tomcat项目将使用中性模块作为war文件依赖项,而maven将进行war覆盖。 So one build would produce both tomcat 5 and tomcat 7 version (and a neutral war file that is not used for deployment). 因此,一个版本将同时生成tomcat 5和tomcat 7版本(以及未用于部署的中性war文件)。

according to http://tomcat.apache.org/whichversion.html the minimum java version from tomcat 5 is java 1.4. 根据http://tomcat.apache.org/whichversion.html,tomcat 5中的最低Java版本为Java 1.4。 But that relates to what the tomcat is running on. 但这与tomcat正在运行的内容有关。 A tomcat 7 should be able to run Java 1.5 bytecode as well. Tomcat 7也应该能够运行Java 1.5字节码。 Just its JDK is 1.6. 只是它的JDK是1.6。 You could use 1.5 for the source and target version of the maven-compiler-plugin to target both version. 您可以将1.5用作maven-compiler-plugin的源版本和目标版本,以同时针对这两个版本。

But I think it should be possible to create a tomcat 5 build that will run on tomcat 7 as well. 但是我认为有可能创建一个也可以在tomcat 7上运行的tomcat 5版本。 Do you have any dependencies that conflict between the two versions? 您是否有两个版本之间有冲突的依赖项? or do you pre-compile the jsp files? 还是您预编译了jsp文件?

For the maven build you will need just one jdk (1.6) to be able to compile sources for an older target version too. 对于Maven构建,您将只需要一个jdk(1.6)就能够为较旧的目标版本编译源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM