Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Problems with JNDI and MailSession

How are you running jetty? Your xml seems to be reasonable, and your .mod file also seems reasonable. I would do a dump after start (java -jar ../jetty-home/start.jar jetty.server.dumpAfterStart=true) and make sure that you see the jars that you are expecting on the correct classpaths.

It seems to me like some kind of classpath error, because the process isn't able to use the jndi ObjectFactory mechanism to convert the MailSessionReference into a mail Session object.

I would also compare against the ee10-demo-jndi webapp. I've had a quick look and the only difference I can see is that we put the mail Session implementation jar onto the classpath via its own module, rather than a [lib] entry in the ee10-demo-jndi.mod file. 

I've also noticed a couple of anomalies in the ee10-demo-jndi setup, for which I will be opening a couple of issues in github, but these aren't related to the problem you're having.

On Fri, 10 Oct 2025 at 04:05, Fawzib Rojas via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
Thanks for the help. I basically copied the ee10-demo-jndi.mod and
created my own mod. I installed the mod without problems, all files
copied and the Datasource works without problems. 

The MailSession still does not work.

Instead of returning jakarta.mail.Session still returning MailSessionReference 
even though the documentation says that lookup for  java:comp/env/mail/Session 
at runtime would obtains a  jakarta.mail.Session.

I get the following exception:

java.lang.ClassCastException: class org.eclipse.jetty.ee10.jndi.factories.MailSessionReference cannot be cast to class jakarta.mail.Session (org.eclipse.jetty.ee10.jndi.factories.MailSessionReference and jakarta.mail.Session are in unnamed module of loader java.net.URLClassLoader @557caf28)

This is what I have in my web.xml for the datasource and mailsession

<resource-ref>
    <res-ref-name>jdbc/DataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
    <res-ref-name>mail/Session</res-ref-name>
    <res-type>jakarta.mail.Session</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

These are my my_webapp.mod,my_webapp.properties and my_webapp.xml files

-- my_webapp.mod --

 [description]
        My Webapp (Module for Jetty)
[environment]
        ee10
[tags]
        webapp
[depends]
        ee10-deploy
        ext
        jdbc
        ee10-plus
        ee10-jndi
[files]
        webapps/my_webapp.war
        webapps/my_webapp.xml 
        webapps/my_webapp.ini 
        maven://jakarta.mail/jakarta.mail-api/2.1.5/jar|lib/ee10/jakarta.mail-api-2.1.5.jar
        maven://jakarta.activation/jakarta.activation-api/2.1.4/jar|lib/ee10/jakarta.activation-api-2.1.4.jar
        maven://org.eclipse.angus/angus-activation/2.0.3/jar|lib/ee10/angus-activation-2.0.3.jar
        maven://org.eclipse.angus/angus-mail/2.0.5/jar|lib/ee10/angus-mail-2.0.5.jar
        maven://com.mchange/c3p0/0.11.2/jar|lib/ee10/c3p0-0.11.2.jar
        maven://com.mchange/mchange-commons-java/0.3.2/jar|lib/ee10/mchange-commons-java-0.3.2.jar
[lib]
        lib/ee10/jakarta.mail-api-2.1.5.jar
        lib/ee10/jakarta.activation-api-2.1.4.jar
        lib/ee10/angus-activation-2.0.3.jar
        lib/ee10/angus-mail-2.0.5.jar
        lib/ee10/c3p0-0.11.2.jar
        lib/ee10/mchange-commons-java-0.3.2.jar
        lib/ee10/jdbcdriver.jar 

--- my_webapp.properties

    environment: ee10

--- my_webapp.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">

<Configure id="wac" class="org.eclipse.jetty.ee10.webapp.WebAppContext">

  <Set name="contextPath">/</Set>
  <Set name="war"><Property name="jetty.webapps" default="." />/my_webapp.war
  </Set>
  <Set name="extractWAR">true</Set>
  <Set name="copyWebDir">false</Set>
  <Set name="configurationDiscovered">true</Set>

  <New id="db" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>
      <Ref refid="wac" />
    </Arg>
    <Arg>jdbc/DataSource</Arg>
    <Arg>
        <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <Set name="DriverClass">???</Set>
            <Set name="JdbcUrl">???</Set>
            <Set name="User">???</Set>
            <Set name="Password">???</Set>
        </New>
    </Arg>
  </New>

  <New id="mailer" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>
      <Ref refid="wac" />
    </Arg>
    <Arg>mail/Session</Arg>
    <Arg>
      <New class="org.eclipse.jetty.ee10.jndi.factories.MailSessionReference">
        <Set name="user">???</Set>
        <Set name="password">???</Set>
        <Set name="properties">
          <New class="java.util.Properties">
            <Put name="mail.smtp.auth">false</Put> <!-- change to true if you want to authenticate -->
            <Put name="mail.smtp.host">???</Put>
            <Put name="mail.from">???</Put>
            <Put name="mail.debug">false</Put>
          </New>
        </Set>
      </New>
    </Arg>
  </New>

</Configure>
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


Back to the top