覆盖应用程序服务器行为,以便在打包的Web应用程序中加载jsp-api和servlet-api jar [英] Overriding application server behaviour for loading jsp-api and servlet-api jars in a packaged web application
问题描述
我有一个使用特定版本的jsp-apiand servlet-api jar文件构建和打包的项目。现在我希望在任何应用程序服务器上部署Web项目时加载这些jar,例如tomcat,WAS,Weblogic等。
I have a project built and packaged with a specific version of jsp-apiand servlet-api jar files. Now I want these jars to be loaded when deploying the web project on any application server for example tomcat, WAS, Weblogic etc.
我在tomcat上看到的行为是它给出的消息是这些api的打包版本没有加载一个有问题的类。
The behaviour I have seen on tomcat is that it gives messages that the packaged version of these apis are not loaded along with an offending class.
我有什么方法可以覆盖这些服务器设置或行为?
Is there any way I could override these server settings or behaviour?
我担心的是,让服务器的默认行为可能允许不同服务器上的不同行为,甚至是同一应用服务器的不同版本。
My concern is that letting the default behaviour of a server may allow different behaviour on different servers or even on different versions of same app server.
推荐答案
- 如果您可以控制要安装此Web应用程序的服务器,则可以将核心jar替换为您的。
- 此外,您可以在应用服务器启动时添加jar。
更新:
至于第二部分,您需要自己修改应用服务器的启动文件。
As for the second part, you'll need to modify the startup file of the application server it self.
我手边没有安装但是假设在目录$ YOUR_APPSERV / bin中有一堆脚本(.cmd或.sh文件)
I don't have an installation at hand but lets suppose in the dir $YOUR_APPSERV/bin there are a bunch of scripts ( either .cmd or .sh files )
其中一些启动应用服务器,还有一些其他帮助来配置它。
Some of them start the app server , some other help to configure it.
您需要修改其中一个命令行如下所示:
You need to modify one of those in such a way the command line look like this:
(假设Windows安装)
(assume a windows installation)
java -Xbootclasspath/p:c:\cutomjars\myJar.jar;customjars\myOtherJar.jar ..................... // the rest of the normal command line.
-bootclasspath / p将罐子添加到app classpath
-bootclasspath/p prepends the jars to the app classpath
-bootclasspath / a将jar附加到app claspath
-bootclasspath/a appends the jars to the app claspath
此选项允许您使用jar中指定的类覆盖JVM中的任何类,因此您如果你愿意,甚至可以替换java.lang.String。
This option let you override any class in the JVM with those specified in the jars, so you can even substitute java.lang.String if you want to.
这是一种方法。不幸的是-Xbootclasspath是Sun JVM的一个选项(即JRockit没有它,也不是IBM的VM,不管他的名字是什么)。
That's one approach. Unfortunately -Xbootclasspath is an option for Sun JVM ( that is JRockit does not have it, nor the IBM's VM what ever his name is )
还有另一个选项你声明所有扩展名都在的文件夹。另外,jre中有一个ext目录。
There was another option where you declare a folder where all the extensions are. Plus, there is an ext directory in the jre.
深入了解你的应用服务器bin目录并找出每个脚本的用途,我很漂亮确定你会完成。
Take a deep dive into your application server bin directory and find out what each script is used for, I'm pretty sure you'll make it through.
以下是对此主题的更正式的解释: http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html
Here's a more formal explanation of this topic: http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html
我希望它有所帮助。
BTW,我用这个年前做的,用旧版本替换CORBA包。所以这肯定有效。
BTW, I use to do this years ago, to substitue the CORBA package with a veeeery old version. So this works for sure.
这篇关于覆盖应用程序服务器行为,以便在打包的Web应用程序中加载jsp-api和servlet-api jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!