Javax activation datasource ошибка

This is the code :

      Session session = Session.getDefaultInstance(props, null);
      Store store = session.getStore("imaps");
      store.connect("imap.gmail.com", "****@gmail.com", "****");
      System.out.println(store);
      Folder folder = store.getDefaultFolder();
      folder = folder.getFolder("INBOX");
      folder.open(Folder.READ_ONLY);

      System.out.println("Message Count: "+folder.getMessageCount());
      System.out.println("Unread Message Count: "+folder.getUnreadMessageCount());


           Message[] messages = folder.getMessages();  --> here the code stops.

      FetchProfile fp = new FetchProfile();
      fp.add(FetchProfile.Item.ENVELOPE);
      folder.fetch(messages, fp);

      for (int i = 0; i< messages.length; i++) 
      { 
          System.out.println("From:"+ messages[i].getFrom()); 
          }

The code gives out the following excption and stops at the point shown.

Exception in thread «main» java.lang.NoClassDefFoundError: javax/activation/DataSource
at com.google.code.com.sun.mail.imap.MessageCache.getMessage(MessageCache.java:129)
at com.google.code.com.sun.mail.imap.IMAPFolder.getMessage(IMAPFolder.java:1394)
at openReports.OpenReports.main

Martin's user avatar

Martin

36.8k15 gold badges73 silver badges82 bronze badges

asked Nov 18, 2011 at 17:26

RaviKiran's user avatar

1

In case you use maven you can add manually

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

vorburger's user avatar

vorburger

3,42931 silver badges38 bronze badges

answered May 28, 2018 at 5:22

jediz's user avatar

jedizjediz

4,4395 gold badges36 silver badges41 bronze badges

3

I added activation.jar to buildpath and the problem is solved.

So i used 2 jars java-mail-ima.** .jar, activation.jar (for further referebces).

answered Nov 19, 2011 at 4:06

RaviKiran's user avatar

RaviKiranRaviKiran

5852 gold badges7 silver badges16 bronze badges

5

On jdk 1.8 I solved this problem by reinstalling jdk and check path in JAVA_HOME and JRE_HOME

answered Nov 11, 2021 at 12:59

JavaSash's user avatar

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

Issue

I’m trying to send Mail using SMTP on netbean when I get the error message:

run: Exception in thread «main» java.lang.NoClassDefFoundError:
javax/activation/DataSource at
SendMail.createMessage(SendMail.java:45) at
SendMail.main(SendMail.java:59) Caused by:
java.lang.ClassNotFoundException: javax.activation.DataSource at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
… 2 more
C:UsersAdminAppDataLocalNetBeansCache12.0executor-snippetsrun.xml:111:
The following error occurred while executing this line:
C:UsersAdminAppDataLocalNetBeansCache12.0executor-snippetsrun.xml:68:
Java returned: 1 BUILD FAILED (total time: 0 seconds)

How do i need to fix it?

(I use Apache NetBeans IDE 12.0;
Java: 15; Java HotSpot(TM) 64-Bit Server VM 15+36-156)

Solution

For classes such as javax.activation.DataSource you need the JAR file for the JavaBeans Activation Framework.

You can download the JAR from Maven Central here — click on the jar link there.

If you are using a dependency management tool such as Maven, Gradle, etc. then use the related configuration (also available in that same page). Using a dependency management tool is strongly recommended over just downloading JAR files one-by-one.


You should also consider replacing your javax imports with jakarta imports, since that is now where these packages are maintained, going forward.

If you do that, then you need to use the Jakarta Activation API, available here. For example:

<dependency>
    <groupId>jakarta.activation</groupId>
    <artifactId>jakarta.activation-api</artifactId>
    <version>2.0.1</version>
</dependency>

And if you do that, you should also replace JavaMail classes too — for example, you can replace this:

import javax.mail.Message;

with this:

import jakarta.mail.Message;

And use a Jakarta Mail resource, for example:

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>jakarta.mail</artifactId>
    <version>2.0.1</version>
</dependency>

Answered By — andrewJames
Answer Checked By — Gilberto Lyons (JavaFixing Admin)

You seem to have included an incorrect artifact(external jar).

You should include javax.activation:javax.activation-api:1.2.0 as an external dependency to your project to explicitly access the class javax.activation.DataSource. Sample maven dependency for the same would be:

<dependency>
  <groupId>javax.activation</groupId>
  <artifactId>javax.activation-api</artifactId>
  <version>1.2.0</version>
</dependency>

Also, note if using modularised code (includes module-info.java), you must state a dependence on the library using declaration —

requires java.activation;

Related videos on Youtube

how to install tomcat in windows 8.1

11 : 47

how to install tomcat in windows 8.1

Setting Apache Tomcat 9.0 with Oracle XE 11g connection

05 : 35

Setting Apache Tomcat 9.0 with Oracle XE 11g connection

#01 How to Install Apache Tomcat on Windows?

10 : 55

#01 How to Install Apache Tomcat on Windows?

Learning Programming Tutorial

Kỹ năng 3: Sửa lỗi java khi nộp tờ khai thuế

05 : 12

Kỹ năng 3: Sửa lỗi java khi nộp tờ khai thuế

Java error: could not find or load main class - Fixed

08 : 08

Java error: could not find or load main class — Fixed

How To Install Java 11.0.1  And Tomcat 9.0.12 Into Ubuntu 18.04

06 : 11

How To Install Java 11.0.1 And Tomcat 9.0.12 Into Ubuntu 18.04

java : how to fix the error : java.lang.UnsupportedClassVersionError

03 : 03

java : how to fix the error : java.lang.UnsupportedClassVersionError

How to add Tomcat Server in eclipse Linux

05 : 39

How to add Tomcat Server in eclipse Linux

java.lang.ClassNotFoundException: com.mysql.jdbc:Driver | MySQL JDBC driver not found - [Solved]

04 : 09

java.lang.ClassNotFoundException: com.mysql.jdbc:Driver | MySQL JDBC driver not found — [Solved]

How To Fix Error Occurred During Initialization of Boot Layer Java Eclipse

00 : 53

How To Fix Error Occurred During Initialization of Boot Layer Java Eclipse

[Solved] How to fix java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

05 : 03

[Solved] How to fix java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

Install Apache Tomcat 9 on Windows 10

11 : 53

Install Apache Tomcat 9 on Windows 10

Easy Fix - Error: Java: invalid target release: 11 - IntelliJ IDEA

02 : 05

Easy Fix — Error: Java: invalid target release: 11 — IntelliJ IDEA

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver | Jdbc error in Netbeans & Eclipse | Solved

04 : 31

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver | Jdbc error in Netbeans & Eclipse | Solved

How to UNINSTALL DELETE REMOVE JAVA JDK in Windows 11

01 : 56

How to UNINSTALL DELETE REMOVE JAVA JDK in Windows 11

Getting an Entity Framework error running migrations on a MySQL database. Incorrect usage of spatia

01 : 30

Getting an Entity Framework error running migrations on a MySQL database. Incorrect usage of spatia

Comments

  • I’m migrating java project use JDK8 to use JDK 11 then has error occurred relate of javax activation.
    Following migration guide from Oracle, I see java.activation that module was removed from JDK 11.

    After that, I give a suggest to added third parties **activation-1.0.2.jar* but still, an error has occurred?
    Please give a suggestion about problem ? and could you tell me about experience of Migration source code use Java 8 to Java 11 (server with tomcat 9.0.12. compiler by Eclipse 2018-09(4.9.0)

    This is detail error :

    Caused by: java.lang.NoClassDefFoundError: javax/activation/DataSource
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167)
        at java.base/java.lang.Class.getDeclaredMethods(Class.java:2310)
        at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:133)
        at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:285)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:138)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:69)
        at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:328)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5007)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    

  • javax.activation:javax.activation-api:1.2.0 is not a module, so requires java.activation has no meaning. In Java 9 and 10, you can use requires java.activation or --add-modules java.activation instead of including the dependency. In Java 11+ the module doesn’t exist in the JDK anymore, so requires java.activation won’t work there.

  • @nullpointer Thank you for your help, I don’t use maven on project now. I’m using java build path. I added javax.activation-api:1.2.0 to external JARs, but that error still occurred ?

  • @Andreas Do you mean that adding external lib is no meaning with java 11 ? Then, could you help me a more detail suggestion for solve this problem ?

  • @Andreas I am aware of the fact that the javax.activation:javax.activation-api:1.2.0 is not a module and hence mentioned it as a dependency(just a way of depicting a complete artifact name). Could not relate to the question being asked in terms of framework in use earlier. And yes, in Java 11 the module is not there, but if you explicitly add the dependency and prefer to have a module-info.java in the project the requires is as valid as in Java 9.10.

  • @SuperBeam While you’re executing the application where do you see the dependency being involved in? Is it present in the classpath?

  • @nullpointer I see the dependency on Properties of project (Java Build Path) of Eclipse. Is that true ?

  • @nullpointer My point was that even if using modularised code, requires java.activation does not state a dependence on the library. Also, since question is about Java 11, not 9 or 10, adding requires java.activation; will actually cause a compilation error, so even mentioning it the way you do is misleading and confusing. If you had said «as an alternative to specifying dependency, in Java 9 and 10 you could …» then mentioning it would be ok, but you didn’t, so it makes the answer incorrect.

  • @Andreas Could you please give me a suggestion correct answer relative in Java 11 ?

  • The above error relate in JDK or Tomcat or Java 11 structure that are modularization ?

  • @Andreas I’m sorry but I don’t think this question is duplicate, I tried to convert my source code to use maven build but this error still appear.

  • I believe developer should also add an implementation of this api, for example com.sun.activation:javax.activation:1.2.0 as a dependency (please, update your answer, if it’s true).

  • for gradle please add this compile ‘javax.mail:mail:1.4.7’

Recents

Related

Hi everyone,

Thanks for reading this. I’ve compiled a simple JavaBean that uses JavaMail and JavaActivationFramework (javax.mail, javax.activation are imported). It is supposed to send mail, and it is very close doing so.

In my jsp page, I’ve included the following lines :

<jsp:useBean id=»sendmail» class=»jspbeans.SendMail» scope=»page»/>
<jsp:setProperty name=»sendmail» property=»host» value=»mail.mycompany.com»/>
<jsp:setProperty name=»sendmail» property=»to» value=»me@mycompany.com»/>
<jsp:setProperty name=»sendmail» property=»from» value=»me@hiscompanyl.com»/>
<jsp:setProperty name=»sendmail» property=»msg» value=»From my jsp page !»/>
<jsp:setProperty name=»sendmail» property=»subject» value=»An alert has been sent to you»/>
<%= sendmail.getMsg() %>

No problems there, my page displays the message, so the Bean is correctly included. But when I had the function call that actually sends the message :
<%sendmail.send()%>
I obtain an annoying error about the activation framework:

————————————————————————
java.lang.NoClassDefFoundError: javax/activation/DataSource
at jspbeans.SendMail.send(SendMail.java:85)
at jrun__process_lits2ejsp11._jspService(jrun__process_lits2ejsp11.java:201)
at jrun.jsp.runtime.HttpJSPServlet.service(HttpJSPServlet.java:43)
at jrun.jsp.JSPServlet.service(JSPServlet.java:110)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:226)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

jrun.jsp.runtime.UncaughtPageException: Unhandled exception thrown from /process_lits.jsp:57
at jrun.jsp.runtime.Utils.handleException(Utils.java:57)
at jrun.jsp.runtime.JRunPageContext.handlePageException(JRunPageContext.java:384)
at jrun__process_lits2ejsp11._jspService(jrun__process_lits2ejsp11.java:206)
at jrun.jsp.runtime.HttpJSPServlet.service(HttpJSPServlet.java:43)
at jrun.jsp.JSPServlet.service(JSPServlet.java:110)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:226)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
————————————————————————

All references to this error points to the CLASSPATH, but I’ve double checked everything. My OS is Windows XP, and my classpath is :
D:oracleora92jdbclibclasses12.zip;D:oracleora92jdbclibnls_charset12.zip;D:Javaj2eesdk1.4_beta2libj2ee.jar;D:Javajaf-1.0.2activation.jar;d:Javajavamail-1.3.1mail.jar

In JRUN console, I’ve added two new classpath entries for the default server, pointing to activation.jar and mail.jar… and I made a copy of activation.jar in about any pertient /lib folder I’ve found on my computer :-)

Please help me, I’m so close to success!

Thanks !

Tom

Возможно, вам также будет интересно:

  • Javascript обработка ошибок promise
  • Javascript как проверить на ошибки
  • Javascript error как устранить ошибку
  • Javascript await fetch обработка ошибок
  • Javascript application выдает ошибку

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии