0+8.52androiandroid是什么意思手机。壳子有吗

How to create a simple EJB3 project in Eclipse (JBoss 7.1) >> the Open Tutorials
Sign In | Register the Open TutorialsExamplesJava EEEJB3How to create a simple EJB3 project in Eclipse (JBoss 7.1) 7 February 2012 By Nithya Vasudevan 149,922 views <span
class="dsq-postid" rel="1085 /?p= Comments
58 Flares &#215; Contents1 Environment Used2 Project Description:3 Creating New EJB Project4 Creating Session Bean and Bean Interface5 Coding Bean and the Interface6 Deploying EJB project7 Start/Restart the Server8 Creating Client8.1 Creating JNDI InitialContext8.2 Creating client class8.3 Setting up EJB client context properties8.4 Adding JAR files required for the client to run the client application8.5 Run the clientEnvironment UsedJDK 6 (Java SE 6)EJB 3.0 (stateless session bean)Eclipse Indigo IDE for Java EE Developers (3.7.1)JBoss Tools – Core 3.3.0 M5 for Eclipse Indigo (3.7.1)JBoss Application Server (AS) 7.1.0.CR1b / FinalSetting up development environment: Read this page for installing and setting up the environment for developing and deploying EJB 3.0 Session bean on JBoss application server.Project Description:We are going to create a simple EJB 3 HelloWorld stateless session bean project and a remote Java application client which will call/invoke the bean.This &#8220;HelloWorld&#8221; example explains how to develop, deploy and run EJB3 Session Bean (stateless and stateful) in JBoss application server.For testing this &#8220;HelloWorld&#8221; example we write a remote Java Application Client (main() method).For simplicity, the session bean and the client to access the session bean are created in the same project.Creating New EJB ProjectOpen Eclipse IDE and create a new EJB project which can be done in three ways,Right click on Project Explorer -> New -> EJB ProjectFile menu -> New -> EJB ProjectClick on the down arrow on New icon on toolbar -> EJB ProjectEnter the project name as &#8220;HelloWorldSessionBean&#8221; and make sure the JBoss 7.1 Runtime has been selected with the EJB 3.0 Module version.Click Next -> Next -> and Finish.You will see an EJB project in the Project Explorer view.Creating Session Bean and Bean InterfaceRight click on ejbModule -> New -> Session Bean (EJB 3.x)Enter the Java package name as com.ibytecode.businesslogicEnter the Class name as HelloWorldBeanSelect the State type as StatelessCheck the Remote Business Interface and enter the name as com.ibytecode.business.HelloWorld. The business interface will be created in different package (com.ibytecode.business)Click FinishCoding Bean and the InterfaceOpen Bean Interface and type the following code and save the file (Ctrl+s).Interface can be either @Remote or @Local. In this example we have used @Remote.
package com.ibytecode.
import javax.ejb.R
public interface HelloWorld {
public String sayHello();
Open Bean and type the following code and save the file.Bean type can either be @Stateful or @Stateless. In this example we have used @Stateless.
package com.ibytecode.
import com.ibytecode.business.HelloW
import javax.ejb.S
@Stateless
public class HelloWorldBean implements HelloWorld {
public HelloWorldBean() {
public String sayHello() {
return &Hello World !!!&;
Now the Stateless Session Bean has been created. The next step is to deploy the bean on the server.Deploying EJB projectNow we need to deploy the stateless session bean “HelloWorldBean” on server.Deploying the project can be done in two ways,Right click on the EJB project -> Run As -> Run On Server. Select the existing “JBoss 7.1 Runtime Server” and click Finish.Right click on “JBoss 7.1 Runtime Server” available in Servers view -> Add and Remove… -> Select the EJB JAR file from the left pane and click Add-> and then Finish.Start/Restart the ServerRight click on “JBoss 7.1 Runtime Server” from Servers view and click on Start if it has not yet been started. If the project is deployed properly with global JNDI mapping then you will see the following message in the console.Creating ClientThe next step is to write a remote Java client application (with main())
for accessing and invoking the EJBs deployed on the server Client uses JNDI to lookup for a proxy of your bean and invokes method on that proxy.Creating JNDI InitialContextObtaining a Context using InitialContextAll naming service operations are performed on some implementation of the javax.naming.Context interface. Therefore, the starting point of interacting with the naming service is to obtain a Context by providing the properties specific to the server implementation being used. In our case it is, JBoss Application Server.To create a javax.naming.InitialContext, we need to initialize it with properties from the environment. JNDI verifies each property&#8217;s value by merging the values from the following two sources,Using parameterized constructor of InitialContext which takes properties of supplied environmentjndi.properties resource files found on the classpath.NOTE:We will use parameterized constructor for initializing the InitialContext.For JBoss AS 7 we need to set the Context.URL_PKG_PREFIXES property with value &#8220;org.jboss.ejb.client.naming&#8221; to obtain the InitialContext.The following utility class is used to create InitialContext for JBoss AS and can be reused in all applications. Otherwise the code written in this class should be repeated in all clients.Right click on ejbModule -> New -> ClassEnter the package name as com.ibytecode.clientutilityEnter the Class name as ClientUtilityClick on Finish
package com.ibytecode.
import java.util.P
import javax.naming.C
import javax.naming.InitialC
import javax.naming.NamingE
public class ClientUtility {
private static Context initialC
private static final String PKG_INTERFACES = &org.jboss.ejb.client.naming&;
public static Context getInitialContext() throws NamingException {
if (initialContext == null) {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
initialContext = new InitialContext(properties);
return initialC
Creating client classRight click on ejbModule -> New -> ClassEnter the package name as com.ibytecode.clientEnter the Class name as EJBApplicationClientCheck the main() method optionClick on Finish
package com.ibytecode.
import javax.naming.C
import javax.naming.NamingE
import com.ibytecode.business.HelloW
import com.ibytecode.businesslogic.HelloWorldB
import com.ibytecode.clientutility.ClientU
public class EJBApplicationClient {
public static void main(String[] args) {
HelloWorld bean = doLookup();
System.out.println(bean.sayHello()); // 4. Call business logic
private static HelloWorld doLookup() {
Context context =
HelloWorld bean =
// 1. Obtaining Context
context = ClientUtility.getInitialContext();
// 2. Generate JNDI Lookup name
String lookupName = getLookupName();
// 3. Lookup and cast
bean = (HelloWorld) context.lookup(lookupName);
} catch (NamingException e) {
e.printStackTrace();
private static String getLookupName() {
The app name is the EAR name of the deployed EJB without .ear suffix.
Since we haven't deployed the application as a .ear,
the app name for us will be an empty string
String appName = &&;
/* The module name is the JAR name of the deployed EJB
without the .jar suffix.
String moduleName = &HelloWorldSessionBean&;
/*AS7 allows each deployment to have an (optional) distinct name.
This can be an empty string if distinct name is not specified.
String distinctName = &&;
// The EJB bean implementation class name
String beanName = HelloWorldBean.class.getSimpleName();
// Fully qualified remote interface name
final String interfaceName = HelloWorld.class.getName();
// Create a look up string name
String name = &ejb:& + appName + &/& + moduleName + &/& +
distinctName
+ &/& + beanName + &!& + interfaceN
Setting up EJB client context propertiesAn EJB client context is a context which contains contextual information for carrying out remote invocations on EJBs. This is a JBoss AS specific API. The EJB client context can be associated with multiple EJB receivers. Each EJB receiver is capable of handling invocations on different EJBs. For example, an EJB receiver &#8220;ClientA&#8221; might be able to handle invocation on a bean identified by app-A/module-A/distinctinctName-A/BeanA!com.ibc.RemoteBeanA, app-B/module-B/distinctName-B/BeanB!RemoteBeanB, etc. Each such EJB receiver knows about what set of EJBs it can handle and each of the EJB receiver knows which server target to use for handling the invocations on the bean. The server IP address and its remoting port should be specified in the properties file placed in the client classpath. This properties file (EJB client context) will then be used internally by the JNDI implementation to handle invocations on the bean proxy.Create a file &#8220;jboss-ejb-client.properties&#8221; in the classpath of the application. We can place it in ejbModule folder of our application. The jboss-ejb-client.properties contains the following properties:remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=falseremote.connections=defaultremote.connection.default.host=localhost remote.connection.default.port = 4447 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=falseAdding JAR files required for the client to run the client applicationOpen Run Configurations… in Run menu or Run Configurations in Run iconSelect the client application (EJBApplicationClient) under Java Application from left pane and open the Classpath tab from right side pane. If you don&#8217;t see your client application, run it once. Select &#8220;User Entries&#8221; and click on &#8220;Add External JARs&#8221;Add the following JAR files.JAR nameLocationjboss-transaction-api_1.1_spec-1.0.0.Final.jarAS7_HOME/modules/javax/transaction/api/main/jboss-ejb-api_3.1_spec-1.0.1.Final.jarAS7_HOME/modules/javax/ejb/api/main/jboss-ejb-client-1.0.0.Beta10.jarAS7_HOME/modules/org/jboss/ejb-client/main/jboss-marshalling-1.3.0.GA.jarAS7_HOME/modules/org/jboss/marshalling/main/xnio-api-3.0.0.CR5.jarAS7_HOME/modules/org/jboss/xnio/main/jboss-remoting-3.2.0.CR6.jarAS7_HOME/modules/org/jboss/remoting3/main/jboss-logging-3.1.0.Beta3.jarAS7_HOME/modules/org/jboss/logging/main/xnio-nio-3.0.0.CR5.jarAS7_HOME/modules/org/jboss/xnio/nio/main/jboss-sasl-1.0.0.Beta9.jarAS7_HOME/modules/org/jboss/sasl/main/jboss-marshalling-river-1.3.0.GA.jarAS7_HOME/modules/org/jboss/marshalling/river/main/You can also add it in Build path (Right click on your EJB Project->Properties, select Java Build Path from left side pane and select Libraries from right side and click on Add External JARs)If you are using JBoss Application Server (AS) 7.1.0 Final version then it is sufficient to add only one client JAR file (jboss-client-7.1.0.Final.jar) which is located in AS7_HOME/bin/clientThe figure below shows the final directory structure of this example. Run the clientUse Ctrl + F11 to run the client. Hello World !!!Related posts:How to setup EJB3 development environment (Eclipse, JBoss 5.1) EJB3 Introduction Installing JBoss Tools in Eclipse Tags: ejb3, ejb3 stateless session bean, jboss as, jboss in eclipse ide, jndi lookup clientNextNo ejb client jar file in classpathIncorrect Lookup nameClient properties file not in classpathSo go through those issues and try again.Pingback: JavaPinsPingback: How To Develop Android Apps In Eclipse | X Power Ionizer PostPingback: Fix Jboss Web 3.0.0 Cr2 Error Report Windows XP, Vista, 7, 8 [Solved]Pingback: EJB/JBoss Sample Returns javax.naming.NoInitialContextException | Solutions for enthusiast and professional programmersFollow @opentutorialsPopular PostsPagination in Servlet and JSP How to create a Servlet with Eclipse and Tomcat How to create a simple EJB3 project in Eclipse (JBoss 7.1) Android: Custom ListView with Image and Text using ArrayAdapter Android: Expandable List View Example How to create and consume a simple Web Service using JAX WS Generate Java class from XML Schema using JAXB &#039;xjc&#039; command How to configure Apache Tomcat in Eclipse IDE? How to create a simple Restful Web Service using Jersey JAX RS API How to create EJB3 JPA Project in Eclipse (JBoss AS 7.1) Recent CommentsBACK TO TOP &

我要回帖

更多关于 android是什么意思 的文章

 

随机推荐