javax.naming.NamingException: Name not found java:/Mail
version:jboss 4.0.1 final
jbuilder10 , cause error code below:
public void test() {
InitialContext ctx = null;
javax.mail.Session session = null;
try {
Properties prop = new java.util.Properties();
prop.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
prop.put(InitialContext.PROVIDER_URL, "jnp://localhost:1099");
prop.put("java.naming.factory.url.pkgs", "org.jboss.naming.client");
try {
ctx = new InitialContext(prop);
}
catch (NamingException ex) {
ex.printStackTrace();
}
Object obj = ctx.lookup("java:/Mail");
System.out.println(obj.getClass());
//javax.naming.Reference ref;
//session =(Session) obj;
session = (javax.mail.Session) PortableRemoteObject.narrow(obj,
javax.mail.Session.class); //java:/Mail java:/
}
catch (Exception ex) {
ex.printStackTrace();
}
//Store store=session.getStore();
// Message msg=store.createMessage();
MimeMessage mm = new MimeMessage(session);
Address[] addrs = null;
try {
addrs = new javax.mail.internet.InternetAddress[] {
new InternetAddress("thliu0987@163.com"),
new InternetAddress("umladp@163.com")};
mm.setFrom();
mm.setRecipients(javax.mail.Message.RecipientType.TO, addrs);
mm.setSubject("title");
mm.setSentDate(new java.util.Date());
mm.setContent("this is a test from jboss!", "text/plain");
//Store st = session.getStore();
//st.connect();
Transport.send(mm);
}
catch (AddressException ex1) {
ex1.printStackTrace();
}
catch (MessagingException ex2) {
ex2.printStackTrace();
}
}
Items bound to the 'java:' namespace can not be accessed remotely.