mailR icon indicating copy to clipboard operation
mailR copied to clipboard

java.lang.NoClassDefFoundError: javax/activation/DataSource

Open ghost opened this issue 6 years ago • 23 comments

Trying to send an email after buying a new MacBook. I have updated all my packages, installed java9 but I am getting this error. I am using this package on another macbook with exactly same settings, so why is this not working?

send.mail(from = sender, to = c("[email protected]"), subject = subject_line, body = "/Users/larsnygaard/table_rank_eod/_html/email.html", html = TRUE, smtp = list(host.name = "smtp.webhuset.no", port = 143,user.name = "[email protected]",passwd = "xxxxxxx", ssl = TRUE), authenticate = TRUE, send = TRUE, debug = TRUE)

Error in .jnew("org.apache.commons.mail.HtmlEmail") : java.lang.NoClassDefFoundError: javax/activation/DataSource

ghost avatar Mar 22 '18 08:03 ghost

I have the same problem, Error in .jnew("org.apache.commons.mail.ImageHtmlEmail") : java.lang.NoClassDefFoundError: javax/activation/DataSource looked everywhere... :( I think it is a java path issue, did you discover anything?

msrodrigues avatar Mar 29 '18 23:03 msrodrigues

Hi ! MailR was working fine on my previous laptop with Java8 installed.

I just got a brand new laptop, installed Java10, fired R/RStudio and... mailR wasn't working anymore. Same error : java.lang.NoClassDefFoundError: javax/activation/DataSource

Quick fix : I installed Java8 (on top of the current Java10), modified the JAVA_HOME system variable to target the right Java version and... voilà ! mailR is working again.

IMO, it boils down to a Java version issue, at least partially.

Hellvince avatar Mar 30 '18 09:03 Hellvince

Same here on Ubuntu 16.04. Forced to upgrade to 18.04 and everything, this breaks and I know nothing about Java.

vfulco avatar Apr 08 '18 05:04 vfulco

mailR will be updated in the coming days; I hope this issue will be resolved.

@Nygdat On my Mac, I use the Java version that comes with the OS. Installing newest Java version from Oracle resulted in a mess.

rpremraj avatar Apr 08 '18 20:04 rpremraj

mailR will be updated in the coming days; I hope this issue will be resolved. This is exciting news! Will it still need java?

msrodrigues avatar Apr 11 '18 03:04 msrodrigues

Sadly yes, because it depends on Commons Email (https://commons.apache.org/proper/commons-email/).

In future I will try to break away from this considering most issues reported here relate to Java.

rpremraj avatar Apr 11 '18 04:04 rpremraj

Hi, encountering same problem. reinstalled java 8 but still facing the same issue. Any suggestions?

shubhangisharma1742 avatar Apr 13 '18 14:04 shubhangisharma1742

Hi, I'm having the same issue with Java 8 Any updates ?

NicolasNeiman avatar May 03 '18 00:05 NicolasNeiman

Same issue hoped to find a fix in-progress via install_github() -> nojoy [mac 10.13.4] Agree: Freedom from Java would solve majority of headaches (a major adoption barrier).

Vancamjr avatar Jun 02 '18 16:06 Vancamjr

Freedom from Java: Agreed!

I am forced to use Java 8 at work, and the package works well... Will upgrade Java libraries as interim solution to see whether it solves current issues.

rpremraj avatar Jun 03 '18 16:06 rpremraj

The Java EE modules are deprecated from Java 9 onwards: http://openjdk.java.net/jeps/320 The general recommendation is providing those modules as dependencies. https://maven.apache.org/surefire/maven-surefire-plugin/java9.html To solve this particular problem it would be "javax.activation:javax.activation-api".

mkroening avatar Jun 06 '18 11:06 mkroening

Hi, I'm having the same issue with Java 9 Any updates ?

wx2000 avatar Jul 28 '18 08:07 wx2000

+1 looking forward to the update...

ghost avatar Aug 11 '18 04:08 ghost

@Hellvince thank you very much for your comment. I was able to take the following steps based on your suggestion. I am using Windows 10, RStudio Version 1.1.456, and R version 3.5.1 (2018-07-02)

Download and install JDK 8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Check if the JAVA_HOME system variable exists or is set from R:

Sys.getenv("JAVA_HOME") # (In my case it was "")

Open a command prompt or Power Shell as an Administrator and enter the following command

rundll32.exe sysdm.cpl,EditEnvironmentVariables

Add a new environment variable for "JAVA_HOME" JAVA_HOME = C:\Program Files\Java\jdk1.8.0_181\jre

Restart RStudio

From there I was able to send emails using:

library(mailR) send.mail( ... ) # Here I was sending emails requiring authentication with a user.name and passwd

I also used debug = TRUE just to see everything was working.

scottyraymond avatar Aug 31 '18 15:08 scottyraymond

I have tried with JAVA11, JAVA 8. But still get following error. Error in .jnew("org.apache.commons.mail.ImageHtmlEmail") : java.lang.NoClassDefFoundError: javax/activation/DataSource

FYI:

Sys.getenv("JAVA_HOME") [1] "/usr/lib/jvm/java-8-oracle"

advait1987 avatar Sep 18 '18 07:09 advait1987

Same problem here. Unable to configure the rJava package. I had to send a lot of emails and I did a workaround: If you are using Linux, you can use mutt, a program to send emails (sudo apt install mutt).

Remember to change the config of muttrc in the following function:

password <- "xxx"
to <- c("[email protected]","[email protected]")
subject <- "test"
body.file <- "body.txt"
attach.files <- c("f1.png","f2.png")
CC <- c("[email protected]","[email protected]")
BCC <- NULL

send_email(password,to,subject,body.file,attach.files=attach.files,CC=CC)

send_email <- function(password,to,subject,body.file,attach.files=NULL,CC=NULL,BCC=NULL){
    ## sudo apt install mutt
    dotmuttrc <- tempfile("muttrc") ##"~/.muttrc"
    configdotmuttrc <- paste0(
        "set smtp_pass=\"",password,"\"\n",
        "set smtp_url='smtp://[email protected]@smtp.office365.com:587/'
set hostname = mycompany.com
set ssl_force_tls = yes
set smtp_authenticators = 'login'
set from = '[email protected]'\n"
)
    cat(configdotmuttrc,file=dotmuttrc)
    command <- paste0("mutt -F ", dotmuttrc," -s '",subject,"' ")
    if(!is.null(CC)) command <- paste(command ,paste(paste0(" -c ", CC),collapse=" "))
    if(!is.null(BCC)) command <- paste(command ,paste(paste0(" -b ", BCC),collapse=" "))
    if(!is.null(attach.files)) command <- paste(command ,paste(paste0(" -a ", attach.files),collapse=" "), " -- ")
    command <- paste(command,paste(to,collapse= " "))
    command <- paste(command, " < ", body.file)
    system(command)
}

emiliotorres avatar Jan 10 '19 00:01 emiliotorres

Hi @rpremraj any news on this topic? I have the same issue with R 3.5.0 / mailR / Java 11. Thanks!

eni0tna avatar Jan 12 '19 20:01 eni0tna

After putting following two jars into system.file("java", package = "mailR"), the issue is resolved on my computer:

  • https://mvnrepository.com/artifact/javax.activation/javax.activation-api/1.2.0
  • https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0

wush978 avatar Feb 20 '19 20:02 wush978

@wush978 , I have used your instruction , but still getting below error:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410) at org.apache.commons.mail.Email.send(Email.java:1437) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at RJavaTools.invokeMethod(RJavaTools.java:386) Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout 60000; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697) at javax.mail.Service.connect(Service.java:386) at javax.mail.Service.connect(Service.java:245) at javax.mail.Service.connect(Service.java:194) at javax.mail.Transport.send0(Transport.java:253) at javax.mail.Transport.send(Transport.java:124) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400) ... 6 more Caused by: java.net.ConnectException: Connection timed out: connect at java.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.base/java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) at java.base/java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148) at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) at java.base/java.net.Socket.connect(Socket.java:591) at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:657) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019) ... 13 more NULL Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465

sdas1983 avatar Mar 15 '19 10:03 sdas1983

Linux Mint 19.2 x86_64-pc-linux-gnu
Kernel: 4.15.0-58-generic R version: 3.6.1 (2019-07-05) RSstudio version: 1.2.1335

The same error here

 Error in .jnew("org.apache.commons.mail.ImageHtmlEmail") : 
 java.lang.NoClassDefFoundError: javax/activation/DataSource

If I run Sys.getenv("JAVA_HOME") ir returns "" after setting with Sys.setenv(JAVA_HOME="/usr/lib/jvm/default-java"); Sys.getenv("JAVA_HOME") returns "/usr/lib/jvm/default-java" But after restart of RStudio the command Sys.getenv("JAVA_HOME") returns again ""

Any ideas how to solve the issue under Linux?

justasmundeikis avatar Aug 23 '19 16:08 justasmundeikis

Thanks to @wush978 I was able to locate the missing jars.

Just download it and copy it to the ...\R-3.6.2\library\mailR\java\ folder.

Important - restart R after copying the jars.

The following JAVA versions seems to work:

#Sys.setenv(JAVA_HOME="C:\java\AdoptOpenJDK\jdk-11.0.6.10-hotspot"); #Sys.setenv(JAVA_HOME="C:\java\AmazonCorretto11\jdk11.0.7_10"); #Sys.setenv(JAVA_HOME="C:\java\OpenJDK8\jdk8u252-b09"); #Sys.setenv(JAVA_HOME="c:\java\Oracle\jre1.8.0_251"); Sys.getenv("JAVA_HOME")

filak avatar Apr 30 '20 22:04 filak

Depois de colocar os seguintes dois frascos system.file("java", package = "mailR"), o problema foi resolvido no meu computador:

  • https://mvnrepository.com/artifact/javax.activation/javax.activation-api/1.2.0
  • https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0

Obrigado, Tbm adicionei ao projeto e funcionou!

cezarags avatar May 29 '20 23:05 cezarags

After putting following two jars into system.file("java", package = "mailR"), the issue is resolved on my computer:

  • https://mvnrepository.com/artifact/javax.activation/javax.activation-api/1.2.0
  • https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0

Thanks @wush978 , after doing this restarting R in R studio worked for me, but you have to install Java 8 and configure it to be default java using update-alternatives. Downloading these jars without user-agent is difficult, so enable a ssh link between this and your local, Download them into your local and secure copy them into remote R server where this issue persists.

absognety avatar Sep 17 '20 08:09 absognety