环境:OS X EI Capitan 10.11.3 + JBoss EAP 6.4.0
1. 创建目录
(1)mkdir -p ~/mygit/CustomModuleTest
(2)cd ~/mygit/CustomModuleTest
(3)mkdir -p aaa/bbb/main aaa/bbb/1.0
2. 创建 1.0 版本的 module
(1)cd ~/mygit/CustomModuleTest/aaa/bbb/1.0
(2)vim Test.java
package aaa.bbb;
public class Test {
static {
System.out.println("nntaaa.bbb.Test class Loaded [VERSION-1.0]");
}
public String sayHello(String name) {
System.out.println("nntaaa.bbb.Test sayHello() called");
return "Mr. " + name;
}
}
(3)vim module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="aaa.bbb" slot="1.0">
<resources>
<resource-root path="Test1.0.jar"/>
</resources>
</module>
(4)javac -d . Test.java
(5)jar cvf Test1.0.jar Test.java aaa/
3. 创建 1.2 版本的 module
(1)cd ~/mygit/CustomModuleTest/aaa/bbb/main
(2)vim Test.java
package aaa.bbb;
public class Test {
static {
System.out.println("nnt[1.2] aaa.bbb.Test class Loaded [VERSION-1.2]");
}
public String sayHello(String name) {
System.out.println("nnt[1.2] aaa.bbb.Test sayHello() called");
return "Mr. [1.2] " + name;
}
}
(3)vim module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="aaa.bbb">
<resources>
<resource-root path="Test1.2.jar"/>
</resources>
</module>
(4)javac -d . Test.java
(5)jar cvf Test1.2.jar Test.java aaa/
4. 把两个 modules 复制到 JBOSS_HOME/modules 目录下
(1)cd ~/mygit/CustomModuleTest
(2)cp -r aaa /Users/maping/Redhat/eap/jboss-eap-6.4/modules/
5. 编写 web 应用
(1)index.jsp
<html>
<head>
<title>JBoss Module Testing
</title>
</head>
<body>
<%
aaa.bbb.Test test=new aaa.bbb.Test();
System.out.println("test.sayHello(JBossAS7) = "+test.sayHello("JBossAS7"));
out.println("test.sayHello(JBossAS7) = "+test.sayHello("JBossAS7"));
%>
Hi Check the Console/Log of your JBoss
</body>
</html>
(2)WEB-INF/web.xml
<web-app>
<display-name>
Module Demo JBposs AS7
</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
(3)WEB-INF/jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="aaa.bbb" slot="1.0"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
6. 测试
启动 EAP
(1)打包并部署应用,访问 http://localhost:8080/my-webapp/index.jsp
会发现此时,在Console中,输出的是1.0版本的信息。
(2)修改WEB-INF/jboss-deployment-structure.xml,去掉slot="1.0",重新打包,发布,访问。
会发现此时,在Console中,输出的是1.2版本的信息。
参考文献:
1. http://middlewaremagic.com/jboss/?p=1933
1. 创建目录
(1)mkdir -p ~/mygit/CustomModuleTest
(2)cd ~/mygit/CustomModuleTest
(3)mkdir -p aaa/bbb/main aaa/bbb/1.0
2. 创建 1.0 版本的 module
(1)cd ~/mygit/CustomModuleTest/aaa/bbb/1.0
(2)vim Test.java
package aaa.bbb;
public class Test {
static {
System.out.println("nntaaa.bbb.Test class Loaded [VERSION-1.0]");
}
public String sayHello(String name) {
System.out.println("nntaaa.bbb.Test sayHello() called");
return "Mr. " + name;
}
}
(3)vim module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="aaa.bbb" slot="1.0">
<resources>
<resource-root path="Test1.0.jar"/>
</resources>
</module>
(4)javac -d . Test.java
(5)jar cvf Test1.0.jar Test.java aaa/
3. 创建 1.2 版本的 module
(1)cd ~/mygit/CustomModuleTest/aaa/bbb/main
(2)vim Test.java
package aaa.bbb;
public class Test {
static {
System.out.println("nnt[1.2] aaa.bbb.Test class Loaded [VERSION-1.2]");
}
public String sayHello(String name) {
System.out.println("nnt[1.2] aaa.bbb.Test sayHello() called");
return "Mr. [1.2] " + name;
}
}
(3)vim module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="aaa.bbb">
<resources>
<resource-root path="Test1.2.jar"/>
</resources>
</module>
(4)javac -d . Test.java
(5)jar cvf Test1.2.jar Test.java aaa/
4. 把两个 modules 复制到 JBOSS_HOME/modules 目录下
(1)cd ~/mygit/CustomModuleTest
(2)cp -r aaa /Users/maping/Redhat/eap/jboss-eap-6.4/modules/
5. 编写 web 应用
(1)index.jsp
<html>
<head>
<title>JBoss Module Testing
</title>
</head>
<body>
<%
aaa.bbb.Test test=new aaa.bbb.Test();
System.out.println("test.sayHello(JBossAS7) = "+test.sayHello("JBossAS7"));
out.println("test.sayHello(JBossAS7) = "+test.sayHello("JBossAS7"));
%>
Hi Check the Console/Log of your JBoss
</body>
</html>
(2)WEB-INF/web.xml
<web-app>
<display-name>
Module Demo JBposs AS7
</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
(3)WEB-INF/jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="aaa.bbb" slot="1.0"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
6. 测试
启动 EAP
(1)打包并部署应用,访问 http://localhost:8080/my-webapp/index.jsp
会发现此时,在Console中,输出的是1.0版本的信息。
(2)修改WEB-INF/jboss-deployment-structure.xml,去掉slot="1.0",重新打包,发布,访问。
会发现此时,在Console中,输出的是1.2版本的信息。
参考文献:
1. http://middlewaremagic.com/jboss/?p=1933
没有评论:
发表评论