EJB3 helloworld 以web形式发布

本文介绍了在使用JBoss部署WAR包过程中需要注意的关键事项,包括避免将特定的JAR文件包含在lib目录下以防止出现异常,以及确保部署Helloworld.jar以避免命名未绑定异常等问题。文中还提供了build.xml文件的具体配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意打war包的时候不能将lib下面Jboss client中的jar打包

否则将抛出异常

java.lang.IncompatibleClassChangeError: Class org.jnp.server.NamingServer does not implement the requested interface org.jnp.interfaces.Naming

此外:以war形式访问,同时需要将Hellowrd.jar部署, 如果不部署Helloworld.jar将会抛出javax.naming.NameNotFoundException: HelloworldBean not bound的异常

附录:

build.xml 文件

<?xml version="1.0" encoding="UTF-8"?> <project basedir="../WebRoot/" default="ejb-war" name="ejb"> <!-- basedir 当前目录, 即表示 WEB-INF/classes文件夹 --> <property name="jboss.deploy" location="D:/IDE/jboss-4.2.3.GA/server/default/deploy"/> <target name="ejb-jar" description="打jar包"> <jar destfile="Helloworld.jar"> <fileset dir="WEB-INF/classes/"> <include name="**/*.class" /> </fileset> <metainf dir="META-INF"> <include name="*.xml"/> </metainf> </jar> </target> <target name="ejb-war" description="打war包"> <war warfile="Helloworld.war" webxml="WEB-INF/web.xml"> <fileset dir="."> <include name="*.jsp" /> </fileset> <classes dir="WEB-INF/classes"> <include name="**/*.class" /> <include name="jndi.properties"/> </classes> <lib dir="WEB-INF/lib"> <include name="*.nojar"/> </lib> </war> </target> <target name="deploy-jar" description="部署jar"> <copy file="Helloworld.jar" todir="${jboss.deploy}"/> </target> <target name="deploy-war" description="部署war"> <copy file="Helloworld.war" todir="${jboss.deploy}"/> </target> </project>

index.jsp

<body> <% try{ Properties props = new Properties(); String jndiPath = this.getClass().getClassLoader().getResource("").getPath(); props.load(new FileInputStream(jndiPath + "/jndi.properties")); InitialContext ctx = new InitialContext(props); System.out.println(ctx.lookup("HelloworldBean/remote").getClass()); Helloworld helloworld = (Helloworld) ctx.lookup("HelloworldBean/remote"); System.out.println(helloworld.sayHello("Spring咖啡...")); }catch(Exception e){ e.printStackTrace(); } %> </body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值