Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: javax/activation/DataSource #77

Open
ghost opened this issue Mar 22, 2018 · 23 comments
Open

java.lang.NoClassDefFoundError: javax/activation/DataSource #77

ghost opened this issue Mar 22, 2018 · 23 comments

Comments

@ghost
Copy link

ghost commented Mar 22, 2018

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("lrs.ngrd@gmail.com"),
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 = "info@norquant.no",passwd = "xxxxxxx", ssl = TRUE),
authenticate = TRUE,
send = TRUE, debug = TRUE)

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

@msrodrigues
Copy link

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?

@Hellvince
Copy link

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.

@vfulco
Copy link

vfulco commented Apr 8, 2018

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

@rpremraj
Copy link
Owner

rpremraj commented Apr 8, 2018

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.

@msrodrigues
Copy link

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

@rpremraj
Copy link
Owner

rpremraj commented Apr 11, 2018

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.

@shubhangisharma1742
Copy link

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

@NicolasNeiman
Copy link

NicolasNeiman commented May 3, 2018

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

@Vancamjr
Copy link

Vancamjr commented Jun 2, 2018

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).

@rpremraj
Copy link
Owner

rpremraj commented Jun 3, 2018

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.

@mkroening
Copy link

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".

@wx2000
Copy link

wx2000 commented Jul 28, 2018

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

@ghost
Copy link
Author

ghost commented Aug 11, 2018

+1 looking forward to the update...

@scottyraymond
Copy link

@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.

@advait1987
Copy link

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"

@emiliotorres
Copy link

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("m1@gmail.com","m2@gmail.com")
subject <- "test"
body.file <- "body.txt"
attach.files <- c("f1.png","f2.png")
CC <- c("a1@gmail.com","a2@gmail.com")
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://me@mycompany.com@smtp.office365.com:587/'
set hostname = mycompany.com
set ssl_force_tls = yes
set smtp_authenticators = 'login'
set from = 'me@mycompany.com'\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)
}

@eni0tna
Copy link

eni0tna commented Jan 12, 2019

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

@wush978
Copy link

wush978 commented Feb 20, 2019

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

@sdas1983
Copy link

@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

@justasmundeikis
Copy link

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?

@filak
Copy link

filak commented Apr 30, 2020

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")

@cezarags
Copy link

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

Obrigado, Tbm adicionei ao projeto e funcionou!

@absognety
Copy link

absognety commented Sep 17, 2020

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests