How to resolve javax/mail/MessagingException? - eclipse

I am using eclipse indigo to run my tomcat server, when I am launching tomcat server, the tomcat server successfully up and running, but with error shown in the console.
ERROR - ContextLoader[177]: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'com.huahsin68.MyBoc' defined in class path resource [my-spring.xml]: Class that bean class [com.huahsin68.MyBocImp] depends on not found; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
java.lang.NoClassDefFoundError: javax/mail/MessagingException
It seems like the MessagingException wasn't found. I have check in the Java Build Path > Libraries, I notice that javax.mail_1.4.0.v200105080615.jar was there. This jar file is locate under eclipse > plugins folder. Is there anything solution to rectify this problem?
THanks #!

With Maven, you can add the following dependency:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
</dependency>

Try the following:
Download the java mail jars from: http://www.oracle.com/technetwork/java/javamail/index-138643.html
Add the jars to your WEB-INF/lib folder
Add the jars to Java Build Path > Libraries
That should do it.

For gradle/android users, in build.gradle (Module app):
compile 'javax.mail:mail:1.4.1'

I had a similar problem, running tomcat stand-alone (that is, not through Eclipse). I copied mail-1.4.jar to my tomcat/lib directory. This worked for me.

For those conning late in this ..
I got the same error resolved by adding below jar.
geronimo-javamail_1.4_mail-1.8.3.jar

Related

Oracle driver ojdbc6 maven dependency error in spring boot application

I am trying to develop spring boot application which will in back-end connect to oracle db.
For oracle db connection I have added ojdbc6 driver dependency. I already have ojdbc6 jar in .m2 folder. But still I am getting compilation error in pom.xml for ojdbc6 dependency 'Missing artifact com.oracle:ojdbc6:jar:11.2.0.3'
As per solutions mentioned on various sites I tried to install ojdbc6 jar using following mvn command :
mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar
But it failed saying artifact already exist:
jar installation error
Error in pom.xml:
You can navigate to .m2 folder, find the path of repository/com/oracle/... and delete the content. then run the command again.
The following solution worked for me:
Download the jar, rename it according to your dependency and paste in the repository folder. For example below path and the dependency:
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
</dependency>
C:\Users\Elias.m2\repository\com\ibm\db2\jcc\db2jcc4\10.1

No Jar found in /WEB-INF/lib after deploying maven project from eclipse to wildlfy9

I am seeing a very strange behavior of wildfly9.x. Build process goes successful. after clicking on RUN AS -> Run on Server(WildFly9.x). It shows exception like NO class def found.
I have already added dependency in POM.xml and its scope is compile.
POM.xml file:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
Exception:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64 from [Module "deployment.worldportfolio.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
Thanks in advance.
I solved it by myself. If you want to run wildfly server from eclipse IDE so you should follow this a very simple method create lib folder in WEB-INF and place all the required Jars in the lib folder. You are done.

JBoss eap 6 JNDI Issue

I am trying out the following tutorial which creates a simple EJB and then accesses via a Java SE client:
http://www.tutorialspoint.com/ejb/ejb_create_application.htm
This tutorial uses ant but I am using maven. Now, in my client, I am getting the following error while creating the initial context:
javax.naming.NoInitialContextException: Cannot instantiate class:
org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at EJBDriver.main(EJBDriver.java:21)
I have added the following dependencies to my pom.xml:
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
Finally, the jndi properties:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:4447
How to solve this issue?
I solved the problem as follows
1- If the EJB classes are in different projects, than the project with EJB classes needs to be added to the classpath of the project containing the client. For Eclipse:
Right Click on project->Build Path->Configure Build Path-> Projects tab->Add->Select the desired project->OK->OK
2- The jboss-client.jar file needs to be added to the class path of the EJB client project as well.
Right Click on project->Build Path->Configure Build Path-> Projects tab->Librariers->Add External JAR
Browse to the jboss-client.jar file(In windows its located in JBoss_Installation/bin/client)
Select the file and click OK twice.
jboss 6 should use the following properties:
naming factory= org.jboss.naming.remote.client.InitialContextFactory
provider url= remote://localhost:4447

How to exclude Eclipse plugin library jars from Tomcat classpath

I have a Spring MVC project that uses Maven imported into Eclipse Kepler SR1 JEE and deployed to Tomcat 7 within Eclipse. Everything was fine until I recently added elasticsearch as a dependency to the Maven pom file and now when I start Tomcat I get an exception
java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet cannot be cast to javax.servlet.Servlet
Launching the server in verbose mode, I see that its because the servlet API is now being loaded from 2 places:
the Tomcat installation folder where it normally comes from
Loaded javax.servlet.Servlet from file:/C:/ProgramFiles/apache-tomcat-7.0.33/lib/servlet-api.jar
but also from one of the Eclipse plugins (Groovy) I have installed
Loaded javax.servlet.Servlet from file:/C:/ProgramFiles/eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar
I can't figure out why this is happening. If I rename the servlet jar file in the plugin's lib folder (i.e. change the extension from .jar to something else so that its not recognized), Tomcat starts up without an exception but that's a hack and so I'd like to know what the cause is and if I'm missing some configuration to exclude plugin library jars from the Tomcat classpath.
Thanks.

Can't use JSTL in JSP page, with project that includes juel-impl jar because of ClassCastException with ExpressionFactoryImpl

The error is:
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [Unable to compile class for JSP] with root cause
java.lang.ClassCastException: de.odysseus.el.ExpressionFactoryImpl cannot be cast to javax.el.ExpressionFactory
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:180)
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:107)
at org.apache.jasper.compiler.PageInfo.<init>(PageInfo.java:79)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:110)
.....
The project is using a war overlay, in which the overlaid project has the juel-impl jar, which is necessary for its use of shindig. Any way to use jstl in the child project jsp pages?
Seems you have two rivaling EL APIs in your class path, tomcat's and another one from your application. Your war file must not contain an el-api.jar or juel-api.jar. Make sure to exclude those dependencies.
The Juel 2.1.3 jar is a combination of the following Jars juel-impl.jar, juel-spi.jar and juel-api.jar.
We had the same issue when we included juel 2.1.3 jar in the pom and deployed in tomcat 7.
The issue is resolved by removing Juel 2.1.3 from pom and by adding only juel-impl.
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.2.6</version>
</dependency>
you need to also add
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
<version>2.2.6</version>
</dependency>
The juel 2.1.3 jar contains the javax/el interfaces and are also a part of jsp-api jar.
I hope this will help.