我用的是jboss 以下是ejb-jar.xml文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ejb-jar (View Source for full doctype...)> - <ejb-jar> - <description> - <![CDATA[ No Description. ]]> </description> <display-name>Generated by XDoclet</display-name> - <enterprise-beans> - <!-- Session Beans --> - <!-- To add session beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called session-beans.xml that contains the <session></session> up for those beans. --> - <!-- Entity Beans --> - <entity> - <description> - <![CDATA[ ]]> </description> <ejb-name>Ejbcmp</ejb-name> <home>com.ejb.test.EjbcmpHome</home> <remote>com.ejb.test.Ejbcmp</remote> <local-home>com.ejb.test.EjbcmpLocalHome</local-home> <local>com.ejb.test.EjbcmpLocal</local> <ejb-class>com.ejb.test.EjbcmpCMP</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.lang.Integer</prim-key-class> <reentrant>False</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>mySchema</abstract-schema-name> - <cmp-field> - <description> - <![CDATA[ Returns the No ]]> </description> <field-name>no</field-name> </cmp-field> - <cmp-field> - <description> - <![CDATA[ Returns the Name ]]> </description> <field-name>name</field-name> </cmp-field> <primkey-field>No</primkey-field> - <!-- Write a file named ejb-finders-EjbcmpBean.xml if you want to define extra finders. --> </entity> - <!-- To add entity beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called entity-beans.xml that contains the <entity></entity> up for those beans. --> - <!-- Message Driven Beans --> - <!-- To add message driven beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called message-driven-beans.xml that contains the <message-driven></message-driven> up for those beans. --> </enterprise-beans> - <!-- Relationships --> - <!-- Assembly Descriptor --> - <assembly-descriptor> - <!-- To add additional assembly descriptor info here, add a file to your XDoclet merge directory called assembly-descriptor.xml that contains the <assembly-descriptor></assembly-descriptor> up. --> - <!-- finder permissions --> - <!-- transactions --> - <!-- finder transactions --> </assembly-descriptor> </ejb-jar>
这个文件已经写了: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd"><jboss> <unauthenticated-principal>nobody</unauthenticated-principal> <enterprise-beans> <!-- To add beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called jboss-beans.xml that contains the <session></session>, <entity></entity> and <message-driven></message-driven> up for those beans. --> <entity> <ejb-name>Ejbcmp</ejb-name> <jndi-name>EjbcmpBean</jndi-name> <local-jndi-name>EjbcmpLocal</local-jndi-name> </entity> </enterprise-beans> <resource-managers> </resource-managers></jboss>还是不行!!!晕啊!
提示错误: javax.naming.NameNotFoundException: EjbcmpBean not bound
我的代码都是从包里面考出来给大家看的,所以打包过程应该没问题.以下是客户端代码:import java.rmi.RemoteException; import java.util.Hashtable;import javax.ejb.CreateException; import javax.naming.InitialContext; import javax.naming.NamingException;/* * 创建日期 2004-3-15 * * 更改所生成文件模板为 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释 *//** * @author houjie * * 更改所生成类型注释的模板为 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释 */ public class Cmptest { private com.ejb.test.EjbcmpHome getHome() throws NamingException { return (com.ejb.test.EjbcmpHome) getContext().lookup( com.ejb.test.EjbcmpHome.JNDI_NAME); } private InitialContext getContext() throws NamingException { Hashtable props = new Hashtable(); props.put( InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099"); // This establishes the security for authorization/authentication // props.put(InitialContext.SECURITY_PRINCIPAL,"username"); // props.put(InitialContext.SECURITY_CREDENTIALS,"password"); InitialContext initialContext = new InitialContext(props); return initialContext; } public void testBean() { try { com.ejb.test.Ejbcmp myBean = getHome().create(); //-------------------------------------- //This is the place you make your calls. //System.out.println(myBean.callYourMethod()); } catch (RemoteException e) { e.printStackTrace(); } catch (CreateException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } } public static void main(String[] args) { Cmptest test = new Cmptest(); test.testBean(); } }
以下是ejb-jar.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ejb-jar (View Source for full doctype...)>
- <ejb-jar>
- <description>
- <![CDATA[ No Description.
]]>
</description>
<display-name>Generated by XDoclet</display-name>
- <enterprise-beans>
- <!-- Session Beans
-->
- <!--
To add session beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called session-beans.xml that contains
the <session></session> up for those beans.
-->
- <!-- Entity Beans
-->
- <entity>
- <description>
- <![CDATA[
]]>
</description>
<ejb-name>Ejbcmp</ejb-name>
<home>com.ejb.test.EjbcmpHome</home>
<remote>com.ejb.test.Ejbcmp</remote>
<local-home>com.ejb.test.EjbcmpLocalHome</local-home>
<local>com.ejb.test.EjbcmpLocal</local>
<ejb-class>com.ejb.test.EjbcmpCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>mySchema</abstract-schema-name>
- <cmp-field>
- <description>
- <![CDATA[ Returns the No
]]>
</description>
<field-name>no</field-name>
</cmp-field>
- <cmp-field>
- <description>
- <![CDATA[ Returns the Name
]]>
</description>
<field-name>name</field-name>
</cmp-field>
<primkey-field>No</primkey-field>
- <!-- Write a file named ejb-finders-EjbcmpBean.xml if you want to define extra finders.
-->
</entity>
- <!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml that contains
the <entity></entity> up for those beans.
-->
- <!-- Message Driven Beans
-->
- <!--
To add message driven beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called message-driven-beans.xml that contains
the <message-driven></message-driven> up for those beans.
-->
</enterprise-beans>
- <!-- Relationships
-->
- <!-- Assembly Descriptor
-->
- <assembly-descriptor>
- <!--
To add additional assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> up.
-->
- <!-- finder permissions
-->
- <!-- transactions
-->
- <!-- finder transactions
-->
</assembly-descriptor>
</ejb-jar>
<jboss> <unauthenticated-principal>nobody</unauthenticated-principal> <enterprise-beans>
<entity>
<ejb-name>Build</ejb-name>
<jndi-name>BuildBean</jndi-name>
<local-jndi-name>BuildLocal</local-jndi-name> </entity>
</enterprise-beans> <resource-managers>
</resource-managers></jboss>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd"><jboss> <unauthenticated-principal>nobody</unauthenticated-principal> <enterprise-beans> <!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jboss-beans.xml that contains
the <session></session>, <entity></entity> and <message-driven></message-driven>
up for those beans.
--> <entity>
<ejb-name>Ejbcmp</ejb-name>
<jndi-name>EjbcmpBean</jndi-name>
<local-jndi-name>EjbcmpLocal</local-jndi-name> </entity> </enterprise-beans> <resource-managers>
</resource-managers></jboss>还是不行!!!晕啊!
javax.naming.NameNotFoundException: EjbcmpBean not bound
import java.util.Hashtable;import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;/*
* 创建日期 2004-3-15
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*//**
* @author houjie
*
* 更改所生成类型注释的模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
public class Cmptest { private com.ejb.test.EjbcmpHome getHome() throws NamingException {
return (com.ejb.test.EjbcmpHome) getContext().lookup(
com.ejb.test.EjbcmpHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable(); props.put(
InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099"); // This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password"); InitialContext initialContext = new InitialContext(props);
return initialContext;
}
public void testBean() { try {
com.ejb.test.Ejbcmp myBean = getHome().create(); //--------------------------------------
//This is the place you make your calls.
//System.out.println(myBean.callYourMethod()); } catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
Cmptest test = new Cmptest();
test.testBean(); }
}
import java.util.Hashtable;import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;/*
* 创建日期 2004-3-15
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*//**
* @author houjie