Problem including commons-email in sample app
wilkowskim Jan 7, 2007 11:23 AMHello,
I created and successfully deployed a sample app. I included commons-email and then the problems started. I get errors NoClassFound. I tried including commons-email.jar in war: WEB-INF/lib and then in the root dir of EAR itself. Unfortunately, I get the error below in both cases.
Below is the log sample:
17:08:49,986 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingC
ontextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
17:08:50,017 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,module=asterisk-admin.jar
java.lang.NoClassDefFoundError: org/apache/commons/mail/EmailException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at org.jboss.injection.InjectionUtil.processMethodAnnotations(InjectionUtil.java:96)
at org.jboss.injection.InjectionUtil.processAnnotations(InjectionUtil.java:172)
at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:270)
at org.jboss.ejb3.SessionContainer.processMetadata(SessionContainer.java:116)
at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:273)
at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:322)
at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy37.start(Unknown Source)
at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:449)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
at org.jboss.ws.integration.jboss.DeployerInterceptor.start(DeployerInterceptor.java:92)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java
:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy38.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy6.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:26
3)
at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy4.start(Unknown Source)
at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy5.deploy(Unknown Source)
at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
at org.jboss.Main.boot(Main.java:200)
at org.jboss.Main$1.run(Main.java:490)
at java.lang.Thread.run(Thread.java:595)
17:08:50,017 INFO [EJB3Deployer] Deployed: file:/C:/java/jboss-4.0.5.GA/server/default/tmp/deploy/tmp477asterisk-admin.
ear-contents/asterisk-admin.jar
17:08:50,017 INFO [TomcatDeployer] deploy, ctxPath=/asterisk-admin, warUrl=.../tmp/deploy/tmp477asterisk-admin.ear-cont
ents/asterisk-admin-exp.war/
17:08:50,126 INFO [ServletContextListener] Welcome to Seam 1.0.1.GA
17:08:50,142 INFO [Initialization] reading components.xml
17:08:50,220 INFO [Initialization] reading properties from: /seam.properties
17:08:50,220 INFO [Initialization] reading properties from: /jndi.properties
17:08:50,220 INFO [Initialization] initializing Seam
Below is the code of the stateless session bean (very simple one) using commons-email:
package com.wolainfo.asterisk.user;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.apache.log4j.Logger;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.FacesMessages;
/**
* Class responsible for user management
*
* @author Michal Wilkowski
*
*/
@Stateless
@Name("userManager")
public class UserManagerBean implements UserManager {
private static Logger log = Logger.getLogger(UserManagerBean.class);
//TODO: email suffix should be a subject to IoC
private String defaultEmailSuffix = "@wolainfo.com.pl";
@In @Out
private User user;
@PersistenceContext
private EntityManager em;
public EntityManager getEm() {
return em;
}
public void setEm(EntityManager em) {
this.em = em;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
/**
* Checks user against LDAP. Not implemented yet.
* @param userName User name to check
* @return FUTURE: True if exists, false - otherwise. PRESENT: As the function is
* not implemented yet it always returns true.
*/
public boolean existsInLDAP(String userName)
{
return true;
}
/**
* Returns user from the local database
*
* @param userName
* @return
*/
public User getUser(String userName)
{
assert userName != null;
Query query = em.createQuery("from User where username = :username");
query.setParameter("username", user.getUsername());
List userList = query.getResultList();
if (userList.size() == 1)
{
return userList.get(0);
}
else if ((userList.size() > 1) || (userList.size() < 0))
{
throw new IllegalStateException("userList.size() = " + userList.size() + " while it should be 0 or 1");
}
else
{
return null;
}
}
/**
* Registers user within the Asterisk SIP users database and sends
* automatically generated password to the user. User is checked against LDAP
*
* @param userName
* @return
*/
public boolean register(String userName)// throws EmailException
{
assert userName != null;
if (existsInLDAP(userName))
{
log.debug("User " + userName + " found in LDAP. Searching database");
User user = getUser(userName);
if (user != null)
{
log.debug("User " + userName + " not found in database. Creating new account");
user = create(userName);
assert user != null;
}
sendPassword(user);
return true;
}
else
{
log.warn("User " + userName + " not found in database. Cannot register");
return false;
}
}
/**
* Sends password notification to the user
*
* @param user
*/
public void sendPassword(User user)// throws EmailException
{
try
{
//TODO: should use IoC
SimpleEmail simpleEmail = new SimpleEmail();
simpleEmail.setHostName("zefir.wolainfo.com.pl");
simpleEmail.setFrom("asterisk@wolainfo.com.pl");
simpleEmail.setSubject("Login i haslo");
simpleEmail.addTo(user.getEmail());
simpleEmail.setMsg("Twoj login: " + user.getUsername() + ". Twoje haslo: " + user.getPassword());
}
catch(EmailException e)
{
log.error("",e);
}
}
/**
* Creates a user account. A password is randomly generated. It assumes that e-mail is @wolainfo.com.pl
* @return Newly created account
*/
public User create(String userName)
{
log.debug("Creating user " + userName);
User user = new User();
user.setUsername(userName);
user.setPassword(generatePassword(userName));
user.setEmail(userName + getDefaultEmailSuffix());
em.persist(user);
log.debug("User (" + user.toString() + ") has just been created");
return user;
}
/**
* Generates password.
* @param userName
* @return
*/
public String generatePassword(String userName)
{
//TODO: requires coding using DES
return "pwd_" + userName;
}
public String getDefaultEmailSuffix() {
return defaultEmailSuffix;
}
public void setDefaultEmailSuffix(String defaultEmailSuffix) {
this.defaultEmailSuffix = defaultEmailSuffix;
}
/**
* Registers user account
*
* @return
*/
public String register()
{
boolean result = register(user.getUsername());
if (result)
{
return "/registered.jsp";
}
else
{
FacesMessages.instance().add("Username does not exist");
return null;
}
}
}
Do you have any idea what might be wrong???
Thanks
Michal