Exception java.lang.NoClassDefFoundError JavaMail Tomcat v8.5 [duplicate] - java

This question already has answers here:
How do I resolve ClassNotFoundException?
(28 answers)
Closed 2 years ago.
I'am trying to send an automatic email with JavaMail on Oracle. I added external JARs on Java Build Path (mail.jar and activation.jar). I don't know what I'm doing wrong because I get this error message:
java.lang.ClassNotFoundException: javax.mail.internet.AddressException
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
I'm using Tomcat v8.5.

You should add Javax mail dependency to make it work.

You need to add the JavaMail library Jars either to the Tomcat lib folder, or it has to be part of your WAR file when you deploy your WebApp. Adding it to the Build Path makes it only available during compile time. Although, depending on the configuration for the Deployment, it could be deployed, too – but obviously, not in your case.

Related

Web application binary location in Tomcat [duplicate]

This question already has answers here:
Where does Eclipse deploy web applications using WTP?
(2 answers)
Closed 14 days ago.
I have dynamic web project in my Eclipse with Java that was used to create simple SOAP web service that runs on Tomcat 9. Service was published and runs fine.
But I can't find where Eclipse puts java class files and other libraries when I start web service. I can't find any changes in Tomcat folder.
I'm usually doing this to find file location of classes
YourClass.getProtectionDomain().getCodeSource().getLocation().getPath()
Replace "YourClass" with any class in your project, debug and evaluate this line, then this will reveal file location.
Also another hint, as per my understanding, a web application can packaged as a war file and can put to tomcat/webapps folder or web application path can be specified manually in a context xml file of tomcat/conf/localhost folder

how can i connect mysql for jdbc i eclipse? [duplicate]

This question already has answers here:
Connect Java to a MySQL database
(14 answers)
Closed 8 months ago.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
got this error also after adding sql-connector-jar to lib of dynamic web project.please help me with this.
at first you need to create a java project and name it
after creating you can see a folder called referenced libraries down to your java project folder
so add your jar which is in this directory (if you have Mysql installed in your system )
C:\Program Files (x86)\MySQL\Connector J 8.0
in this folder you can find the .jar add to the referenced libraries
and start executing the code it will work
or execute this
Class.forName("com.mysql.cj.jdbc.Driver");
this might work

How to correct eclipse tomcat server error [duplicate]

This question already has answers here:
Multiple contexts with the same path error running web service in Eclipse using Tomcat
(24 answers)
Closed 4 years ago.
I got following error when I tried to run a project on eclipse. Can someone please explain what can be done to resolve it.
Could not publish server configuration for Tomcat v7.0 Server at localhost.
Multiple Contexts have a path of "/CityHotel".
Multiple Contexts have a path of "/OOPEmployeeWebApp".
Possibly you have a context configured in Eclipse and a WAR file deployed in the Tomcat webapps directory, both with the same name.
check your tomcat folder and /conf and server.xml, and remove the duplicated contexts
It should be a configuration problem, might be you need some server specific configs you didnt set, thus it is throwing the error.
It could also be an actual duplication error, in which case check all class paths for duplications.

Eclipse servlet error [duplicate]

This question already has answers here:
How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
(16 answers)
Closed 7 years ago.
I was working with a fully functional .war file I imported for a intro to Java tutorial I'm following. I had to change the jdk I was using (via the installed jre page). Now after changing this I'm getting a "javax.servlet cannot be resolved" error with my code. Anyone have any ideas?
check project build path whether Servlets api. jar file is included or not. you can add it in two ways:
1) add servlets api .jar file to build path
or
2) add server runtime (i add Tomcat server runtime library) in build path
Hope this helps.

jars shipped in war conflicting with jetty [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.runtime.ELContextImpl
I export a web service project (contains jsp pages) from Eclipse in a war file and deploy it in Jetty 8.1.5. It works fine on my machine. But after deploying the same war file on Jetty 8.1.3 on another machine (windows server 2003) it gives HTTP Error 500 and the following exception when I go to the index.jsp page:
org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.runtime.ELContextImpl
the full trace and more details in this question which I posted two days ago. while all the jars that I have in WEB_INF/lib are provided in these two screenshots:
two days of looking around the internet for a solution resulted in knowing that the problem is caused by conflicts between the jars shipped in the war file and other jars (I guess the jetty jars).
The question is: how can I find out which jar is causing the problem? I tried browsing the contents of these jars looking for the class ElContextImpl but did not find anything ?
Any thoughts?
EDIT:
I tried copying my local whole Jetty 8.1.5 into the server and statrted jetty from there.. but still no success.
Your WAR file contains some unnecessary JARs like servlet-api-2.4.jar which should be part of the Jetty installation (maybe in another version).
At first sight you should remove all jetty-*.jar, servlet-api-2.4.jar, javax.servlet.*.jar. If you have taken these from your 8.1.5 Jetty installation then it could cause conflicts with your 8.1.3 installation.

Categories