java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream - java

I'm trying to send an email through Java Mail API and it works fine on my laptop. When I'm doing exactly the same in Heroku, I'm getting this:
java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream.(Ljava/io/InputStream;Lcom/sun/mail/util/MailLogger;)V
at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:2014)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1936)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:291)
at ...
Here is what I have in pom.xml:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.3</version>
<scope>runtime</scope>
</dependency>
I guess there is another version of Java Mail API inside Heroku JDK, which doesn't have this constructor... How can this be fixed?

By default, Java apps running on latest Heroku stack use OpenJDK 8.
Your problem does not seems related to the actual JVM implementation but rather due to the missing smtp-1.5.1.jar in classpath . To be sure to load correctly TraceInputStream try this :
java.net.URL classUrl = this.getClass().getResource("com.sun.mail.util.TraceInputStream");
out.println(classUrl.getFile());

I also faced the same issue. It was because I don't have the class TraceInputStream inside the library. I simply downgrade libraries to 1.4.4 and it worked.
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.4</version>
</dependency>

You've mixed different versions of the API and implementation; don't do that. For that matter, you only need the com.sun.mail:javax.mail dependency. If Heroku isn't providing it in the runtime environment, you'll need to package it in your application. Make sure the JavaMail jar file is ending up in the WEB-INF/lib directory of your application.

Getting reference from #Osanda Deshan. Adding below gradle dependencies Worked for me.
implementation 'javax.mail:javax.mail-api:1.4.4'
implementation 'javax.mail:mail:1.4.4'

Related

Class not found com.sun.ws.rs.ext.RuntimeDelegateImpl on ubuntu tomcat

I'm using GWT/P to build a webapp which uses javax.ws.rs.client to communicate with rest services.
Jersey client is used:
<jersey.version>2.22.2</jersey.version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
It's deployed on tomcat (7 and 9 versions, both work as expected). However, on one ubuntu server, using tomcat 9 I get following exception:
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69)
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:80)
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:99)
at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:71)
at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:290)
at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:76)
I don't know why is it looking for com.sun.ws.rs.ext.RuntimeDelegateImpl instead of org.glassfish.jersey.internal.RuntimeDelegateImpl, and that it happens only on that particular server (windows, amazon AWS linux, docker linux works fine).
I have tried increasing jersey version to 2.27 (can't increase it more, since newer versions conflict with GWT jetty 9.2.14).
I have tried adding META-INF/services/javax.ws.rs.ext.RuntimeDelegate with first line as org.glassfish.jersey.internal.RuntimeDelegateImpl.
Nothing seems to work. What am I missing here? Any ideas?
gwt-rest-dispatch was including jsr311-api.jar, which was causing the issues.
Removing this dependency (since my project does not use it) solved this.
I had a problem similar to yours, I forced the deletion of the jsr311-api dependency from the pom.xml, so I rebuilt it and it worked.
I believe the dependency UriBuilder conflicts with AWS dependencies,
When I used it, Spring itself downloaded 2.0.11 and the dependency I used was 0.0.11, that's when I deleted both.

java.lang.NoSuchMethodError: com.google.common.base.Preconditions

Im getting this error
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
Im building a bot for social media , so Im using Selenium libraries, and the bot works fine on a Java Application , but when I copy the code to a Web Application where I have a Servlet listening to my Android application , when I run the servlet , and the servlet calls the code of the bot that use Selenium, it throws that error when it comes to that line
System.setProperty("webdriver.chrome.driver", "C:\\Users\\manue\\OneDrive\\Escritorio\\chromedriver.exe");
driver = new ChromeDriver();
I had read that it can be becouse of the version of guava that I have , but my version of guava is updated , and I dont know why Im getting this error.
In my maven pom.xml I have the dependencies like this
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.10.0</version>
</dependency>
Here there is a screenshot of the structure of my project.
screenshot of my project
I found a solution to a possibly related error message when I removed the Google Collections jar from the lib path.
(Source)
Looks like a classpath issue. What version of guava-X.jar do you have in our classpath? (most probably in WEB-INF/lib of webapp). Possible solution is to declare latest version of guava in your pom.xml explicitly. For 3.10.0 of selenium, you need:
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>

java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException

I have created a Web Service using Spring. It works fine when running it on my embedded tomcat server. However when I package it as a JAR file and run it with java -jar command, I am receiving this exception.
My service sends a simple soap request and the server response is:
"exception": "java.lang.NoClassDefFoundError",
"message": "javax/xml/soap/SOAPException",
That's the response I get in Postman.
Any ideas where I can look for the problem.
Adding the following in pom file solved the issue
<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
JavaSE 8 includes package java.xml.soap.
JavaSE 9 moved package javax.xml.soap to the module java.xml.ws.
Modules shared with JEE (like java.xml.ws) are included in JavaSE 9, but are
- deprecated for removal from a future version of JavaSE, and
- not on the default module path.
A quick workaround is to either
- run the jar with JRE 8: $MY_JRE8_HOME/bin/java -jar my.jar, or
- add a module for JRE 9: java --add-modules java.xml.ws -jar my.jar
Longer term, JavaSE projects that use modules like java.xml.ws must explicitly include the module like other libraries.
See https://stackoverflow.com/a/46359097
See JDK 9 Migration Guide: Modules Shared with JEE Not Resolved by Default
(Reproduced NoClassDefError and workarounds with zipped SOAP web service project at https://spring.io/guides/gs/producing-web-service/)
Yes, In Java 11 java.xml.soap was completely removed.
java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException can be removed by adding the
following dependency.
<dependency>
<groupId>jakarta.xml.soap</groupId>
<artifactId>jakarta.xml.soap-api</artifactId>
<version>2.0.0-RC3</version>
</dependency>
But later, you will encounter , javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found.
This can be solved by adding the following dependency.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
Hope, it helps!
Add the following dependencies, it should work then
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.6</version>
</dependency>
Refer the following links for a running piece of code (SpringBootSOAPWS + Java10)
Github- SpringBoot Soap Server
Github- SpringBoot Soap Client
I imported this one to sort out the issue: https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api/1.4.0
Adding this dependency will solve the issue.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
The JAX-WS dependency library “jaxws-api.jar” is missing.
Try:
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' - for gradle or:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
I know this is already closed for all above people but I am still facing this issue even though I have added
jakarta-xml.soap-api and saaj jars in classpath.
Anything that I am missing to make it work.Tried out using javax-.xml-soap-api as well instead of jakarta jar but still same error.Somehow its not able to identify the jar.

JAVA - com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found

I'm working on an application that consumes a web service using SOAP requests.
Sometimes I get this error:
filters.LoggerFilter:92 - org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.Error: javax.xml.soap.SOAPException: Unable to create SAAJ meta-factoryProvider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
The weird part is that I get this error randomly, but I can't seem to figure out the cause.
I even added a new dependency, but it doesn't seem to correct the issue:
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency>
I just had the same problem while using Java 11 to create an application that consumes SOAP-requests.
I added the new dependency and it worked fine for me.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
For me, I was using Java 13 and the following worked for me(add these in the pom.xml)
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-api</artifactId>
<version>2.4.4</version>
</dependency>
For those who face this issue in intellij IDEA using Spring Boot under Java SDK 9+, you have to include explicitly --add-modules java.se.ee in VM parameters (edit configurations -> VM options). This answer may help to resolve other importing issues related to new Java Modules
I had the same problem.
For me, adding saaj-impl was not enough to get rid of the exception
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.2</version>
</dependency>
I had to also add saaj-api which fixed it finally:
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
Since I realised that my application was using saaj-api 1.3.4 after checking with command, upgrading to 1.3.5 helped
mvn dependency:tree -Dverbose
Change your project sdk as Java 1.8
If you are using import javax.xml.ws library it could be confusing com.sun.xml.messaging.saaj dependency in Java 11. Clearing saaj dependency then using Java8 may be a solution in this issue
With open JDK 17 and spring boot 3.0.1, I was getting the same issue. It got resolved by adding these dependencies in pom.xml
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-api</artifactId>
<version>2.4.4</version>
</dependency>

NoClassDefFoundError: Mockito Bytebuddy

I recently added Mockito to a maven project on eclipse, by adding the external jar "mockito-core-2.0.53-beta.jar", and upon attempting to create my first mock object (Line two in the function)
And upon running it, the console prints out the first line, then throws this error:
It seems like previously there was a similar issue, but it was supposedly fixed internally. https://github.com/raphw/byte-buddy/issues/99
What is going wrong here?
You simply forgot to add the dependencies to your project which are according to the pom file:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.3.16</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>runtime</scope>
</dependency>
In other words you need to add byte-buddy 1.3.16 and objenesis 2.1 to your project too.
More details here
Instead adding
mockito-core
better option will to add
mockito-all
Refer to this link https://mvnrepository.com/artifact/org.mockito/mockito-all/2.0.2-beta
There is a post that explain the problem pretty well, you can find it here:
https://solidsoft.wordpress.com/2012/09/11/beyond-the-mockito-refcard-part-3-mockito-core-vs-mockito-all-in-mavengradle-based-projects/
If you are not using gradle or maven and you are just using mockit-core you should add these dependencies:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.7.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.4</version>
<scope>runtime</scope>
</dependency>
java.lang.NoClassDefFoundError
This indicates that in your .jar (org.mockito), you don't have that class.
This usually occurs when you have more than one .jar (with a different version) in your classpath. You could check that.

Categories

Resources