您的位置:首页 > 编程语言 > Java开发

jboss-as-7.1.1.Final:(四)Eclipse集成下的自动发布和JSP的热加载

2016-04-06 18:52 513 查看

一、自动发布设置

首先我们要理解
auto-publish
auto-deploy
的区别,前者只是源文件的替换,而后者是这个项目的重新部署,显然敲代码时使用前者更加便捷。JBoss配置如图:



Publishing设置为:Automatically publish when resources change,不要勾选Use auto-deploy mode选项。

二、JSP的热部署

设置好自动发布后,需要知道的是JSP被服务器编译成class文件才能作为资源使用的,所以光是替换JSP源文件是无效的,而jboss-as-7.1.1.Final就存在这个问题,那该怎么解决呢?以单机模式为例:

[b]1. 修改服务器配置文件[/b]

在配置文件
$JBOSS_HOME1/standalone/configuration/standalone.xml
中找到
xmlns
urn:jboss:domain:web:1.1
subsystem
节点:

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="true">
......
</subsystem>


添加如下子节点:

<configuration>
<jsp-configuration development="true"/>
</configuration>


[b]2. 修改源码[/b]

打开目录
$JBOSS_HOME/modules/org/jboss/as/web/main
,看到
jboss-as-web-7.1.1.Final.jar
有木有?利用反编译工具,我们在包中找到类
org.jboss.as.web.WebSubsystemAdd
的这个方法
resolveConfiguration
,其源码为:

private ModelNode resolveConfiguration(OperationContext context, ModelNode model) throws OperationFailedException {
ModelNode res = new ModelNode();
for (AttributeDefinition attr : WebContainerDefinition.CONTAINER_ATTRIBUTES) {
res.get("container").get(attr.getName()).set(attr.resolveModelAttribute(context, model));
}
for (SimpleAttributeDefinition attr : WebStaticResources.STATIC_ATTRIBUTES) {
res.get("static-resources").get(attr.getName()).set(attr.resolveModelAttribute(context, model));
}
for (SimpleAttributeDefinition attr : WebJSPDefinition.JSP_ATTRIBUTES) {
res.get("jsp-configuration").get(attr.getName()).set(attr.resolveModelAttribute(context, model));
}
return res;
}


其方法体修改为:

ModelNode res = new ModelNode();
ModelNode unresolvedContainer = model.get("container");
for (AttributeDefinition attr : WebContainerDefinition.CONTAINER_ATTRIBUTES) {
res.get("container").get(attr.getName()).set(attr.resolveModelAttribute(context, unresolvedContainer));
}
ModelNode unresolvedStaticResources = model.get("static-resources");
for (SimpleAttributeDefinition attr : WebStaticResources.STATIC_ATTRIBUTES) {
res.get("static-resources").get(attr.getName()).set(attr.resolveModelAttribute(context, unresolvedStaticResources));
}
ModelNode unresolvedJspConf = model.get("jsp-configuration");
for (SimpleAttributeDefinition attr : WebJSPDefinition.JSP_ATTRIBUTES) {
res.get("jsp-configuration").get(attr.getName()).set(attr.resolveModelAttribute(context, unresolvedJspConf));
}
return res;


然后重新编译打包,可命名为:
jboss-as-web-7.1.1.Final-RECOMPILE.jar
,与
jboss-as-web-7.1.1.Final.jar
同目录放置,同时将该目录下文件
jboss-as-web-7.1.1.Final.jar.index
重命名为
jboss-as-web-7.1.1.Final.jar-RECOMPILE.index


[b]3.修改模块描述文件[/b]

在相同目录中,打开
module.xml
文件,找到标签:

<resource-root path="jboss-as-web-7.1.1.Final.jar"/>


将其修改为:

<resource-root path="jboss-as-web-7.1.1.Final-RECOMPILE.jar"/>


至此JSP的热加载就大功告成。

JBoss的安装根目录。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jboss