Tomcat web project calls JBoss's EJB

Source: Internet
Author: User

I learned how to call EJB in JBoss.

Then I learned how to call JBoss's EJB FOR THE WEB Project in Tomcat.

Environment:

Tomcat5.5 + jboss4.0.4

First, create a Java project in eclipse.

Create two files

Helloworld. Java

Package com;

Public interface helloworld {

Public String sayhello (string name );

}

 

Helloworldbean. Java

Package com;

IMPORT javax. EJB. Remote;

IMPORT javax. EJB. stateless;

@ Stateless

@ Remote ({helloworld. Class })

Public class helloworldbean implements helloworld {

Public String sayhello (string name ){

// Todo auto-generated method stub

Return name + "is the first remote EJB ";

}

}

Put the jboss-ejb3x.jar under JBoss in the classpath of the project.

Then package it into helloworld. Jar

Deploy to the C: \ jboss-4.0.4.GA \ Server \ All \ deploy directory.

The JBoss console is displayed.

Create a web project.

Testhello

Create an index. jsp

<% @ Page Language = "Java" contenttype = "text/html; charset = ISO-8859-1"

Pageencoding = "ISO-8859-1" %>



<HTML>

<Head>

<Title> the first EJB </title>

</Head>

<Body>

<%

Java. util. properties props = new java. util. properties ();

Props. setproperty ("Java. Naming. Factory. Initial", "org. jnp. Interfaces. namingcontextfactory ");

Props. setproperty ("Java. Naming. provider. url", "localhost: 1099 ");

Props. setproperty ("Java. Naming. Factory. url. pkgs", "org. JBoss. Naming ");

Javax. Naming. initialcontext CTX;

Try {

CTX = new javax. Naming. initialcontext (props );

Com. helloworld = (COM. helloworld) CTX. Lookup ("helloworldbean/remote ");

Out. println (helloworld. sayhello ("Michael "));

} Catch (javax. Naming. namingexception e ){

E. printstacktrace ();

}

%>

</Body>

</Html>

 

Put these 6 jar: jboss-aop-jdk50.jar, jboss-aspect-library-jdk50.jar, jboss-ejb3.jar, jboss-remoting.jar. Put in the classpath of the project.

Then package it into testhello. War.

Deploy to Tomcat

Then run the command to obtain the result on the interface.

Michael is the first remote EJB

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.