开发工具:
eclipse mars
wildfly
jdk8
maven
右键新建project,选择other
勾选create simple project
填写信息(自行填写),完成后右键项目,选择properties,选择project facets ,点convert to 。。。
选择如下:ok
修改项目根目录下的pom.xml
加入(否则引入EJB包是找不到)
</pre><pre name="code" class="html"><span style="white-space:pre"> </span><dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> </dependencies>
右击src/main/java 新建session Bean
填写如下
编写类方法(自己下项目看,结尾有)
maven 发布项目
用maven新建的web项目,这里不介绍
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="com.accen.demo.*"%> <%@ page import="javax.naming.InitialContext"%> <%@ page import="javax.naming.Context"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <%!HelloRemote helloRemote;%> <%!HelloLocal helloLocal;%> <% Context context = null; try { context = new InitialContext(); helloRemote = (HelloRemote) context .lookup("global/ejbdemo/Hello!com.accen.demo.HelloRemote"); helloLocal = (HelloLocal) context .lookup("global/webdemo/Hello!com.accen.demo.HelloLocal"); } catch (Exception e) { e.printStackTrace(); } %><p> <h1>Constants</h1> PI: <%=helloRemote.getPI1()%> <%=helloLocal.getPI() %><br> </body> </html>
运行结果:
项目连接
http://download.****.net/detail/edwards_june/9506785