The first time I wrote an EJB summary!

Source: Internet
Author: User
Tags jboss server
I plan to learn EJB this month. I read the first three chapters and found it messy. It turns out that EJB is not so easy to learn. The first helloworld took 4 hours, but finally heard the sound of EJB. I will not talk about the specific process. I will mainly write down the mistakes that cainiao's friends may make, just like me. You are also welcome to give me some advice.

I use JBoss + eclipse.

There is nothing to say about JBoss installation, remember to add in the environment variables after installation: jboss_home = C:/jboss-4.0.2 (here is the path to your JBoss installation ), add % jboss_home %/bin to path.

The JBoss directory structure is helpful for beginners.
Bin: JBoss switch scripts
Client
: Client libraries (jars) used for communication with JBoss)
Docs
: Set the document sample. (For example, set the document sample in the information library)
Docs/DTD
: Document Type Definitions (dtds) files for different XML files in JBoss.
Lib
: When JBoss is started, libraries shared by different configurations will be read here.
Server
: Stores different JBoss configuration files.
Server/Default
: Configuration file preset by JBoss.
Server/default/Conf
: JBoss configuration file.
Server/default/Data
: JBoss database.
Server/default/deploy
: JBoss Automatically releases the detection directory. (If ebj-jars, wars, and ears are released, JBoss automatically detects the directory)
Server/default/lib
: When JBoss starts this configuration directory, it will read libraries.
Server/default/log
: Stores JBoss log files.
Server/default/tmp
: Stores JBoss files.
Server/default/work
: Stores the compiled JAVA byte code of JBoss.

Note:
1: ejb-jar.xml is placed in the META-INF folder, if you want to build JBoss. XML is also put here.
2: If you run the client code and JBoss server on the same machine, the following code can be run without any modification,
Env. Put (context. provider_url, "localhost: 1099 ");
You can change the IP address on another machine.
3: If you encounter exceptions such as classnotfound during running, it means you have not imported the package. Just import it. I now run to import 2 packages, jnp-client.jar, jbossall-client.jar, they are in the client directory under JBoss.
4: I can see many pieces of JBoss. XML are written on the Internet. After I run it, I understand that it is used to set up JNDI. In fact, it is as simple as we do not need to set up JBoss. xml.
Remember: Object OBJ = CTX. Lookup ("hello"); here "hello" is your <EJB-Name> value in the ejb-jar.xml, If you create
If JBoss. XML is used, "hello" should be replaced with the value of <JNDI-Name>.

Here is my JBoss. xml:

<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype JBoss public "-// JBoss // DTD JBoss 4.0 // en" "jboss_4_0.dtd">
<JBoss>
<Enterprise-beans>
<Session>
<EJB-Name> Hello </EJB-Name>
<JNDI-Name> example/Hello </JNDI-Name>
</Session>
</Enterprise-beans>
</JBoss>

Helloclient. Java:

Package example;
Import javax. Naming. context;
Import javax. Naming. initialcontext;
Import javax. Naming. namingexception;

Import java. util .*;

Public class helloclient ...{

/***//**
* @ Param ARGs
*/
Public static void main (string [] ARGs )...{
// Todo auto-generated method stub
Hashtable Env = new hashtable ();

Env. Put (context. initial_context_factory, "org. jnp. Interfaces. namingcontextfactory ");
Env. Put (context. provider_url, "localhost: 1099 ");
Env. Put ("Java. Naming. Factory. url. pkgs", "org. JBoss. Naming: org. jnp. interfaces ");

Try ...{
Context CTX = new initialcontext (ENV );
Object OBJ = CTX. Lookup ("hello ");

Hellohome home = (hellohome) javax. RMI. portableremoteobject. Narrow (OBJ, hellohome. Class );
Hello = home. Create ();

System. Out. println (hello. hello ());

Hello. Remove ();
} Catch (exception e )...{
// Todo auto-generated Catch Block
E. printstacktrace ();
System. Out. println (E. getmessage ());
}
}

}

The above are some of my experiences and I hope to help beginners.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.