0

OK, this is baffling me. I am trying to get the jetty maven plugin running with mail. I am restricted to 6.1.15 because we are using JDK 1.6.

I keep on getting this exception.

org.springframework.beans.factory.BeanCreationException: Error creating bean with nam 'mailService' defined in ServletContext resource [/WEB-INF/spring-agenttools.xml]:

Instantiation of bean failed; nested exception is  org.springframework.beans.BeanInstantiationException: Could not instantiate bean class  [com.tttt.iss.agenttools.util.MailService]: Constructor threw exception; nested exception is  

java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session

I have configured the plugin like this. If I remove all mail.jar from the classpath my code will not work. If I do add it, I get the Exception

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>${jetty.version}</version>
            <configuration>

                <!-- 
                <webApp>${basedir}/target/agenttools.war</webApp>
                 -->
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8080</port>
                        <maxIdleTime>30000</maxIdleTime>
                        <headerBufferSize>8192</headerBufferSize>
                    </connector>

                    <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
                        <port>8443</port>
                        <maxIdleTime>30000</maxIdleTime>
                        <headerBufferSize>8192</headerBufferSize>
                        <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
                        <password>jetty6</password>
                        <keyPassword>jetty6</keyPassword>
                    </connector>

                </connectors>

                <jettyEnvXml>src/main/webapp/WEB-INF/jetty-web.xml</jettyEnvXml>
                <useProvided>false</useProvided>
                <webAppConfig>
                    <defaultsDescriptor>${basedir}/src/test/resources/webdefault.xml</defaultsDescriptor>
                    <contextPath>/</contextPath>
                    <!-- Defining the extraClasspath is tricky. Please leave it on one line. Multiline works in windows but it fails in a linux environment -->
                    <extraClasspath>${basedir}/target/agenttools</extraClasspath>
                    <baseResource implementation="org.mortbay.resource.ResourceCollection">
                        <resourcesAsCSV>src/main/webapp</resourcesAsCSV>
                    </baseResource>
                </webAppConfig>

                <systemProperties>
                    <systemProperty>
                        <name>java.naming.factory.initial</name>
                        <value>org.mortbay.naming.InitialContextFactory</value>
                    </systemProperty>
                    <systemProperty>
                        <name>build.compiler</name>
                        <value>com.ttt.cs.is.ttt.jetty.JDTCompiler16</value>
                    </systemProperty>
                    <systemProperty>
                        <name>log4j.configuration</name>
                        <value>log4j-jetty.properties</value>
                    </systemProperty>
                </systemProperties>
                <stopPort>9966</stopPort>
                <stopKey>halt</stopKey>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>javax.activation</groupId>
                    <artifactId>activation</artifactId>
                    <version>${activation.version}</version>
                </dependency>
                <dependency>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                    <version>${mail.version}</version>
                </dependency>
                <dependency>
                    <groupId>antlr</groupId>
                    <artifactId>antlr</artifactId>
                    <version>2.7.7</version>
                </dependency>
                <dependency>
                    <groupId>xalan</groupId>
                    <artifactId>serializer</artifactId>
                    <version>${xalan.version}</version>
                </dependency>
                <dependency>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                    <version>${xalan.version}</version>
                </dependency>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.33</version>
                </dependency>

            </dependencies>
        </plugin>

How can I get this working? I am using the javax.mail:mail:1.4. The same as the Jetty version.

As it possible to exclude or override the Jetty Plugin mail ?

Note, the mail.jar is added only once to the classpath.

UPDATE

When I totally remove the mail.jar, the app starts, but I get the following issue. So now I only have one mail.Session but not the rest.

Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.SharedByteArrayInputStream
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:242)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:379)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:341)

Thanks for your help, Coenos

Coen Damen
  • 2,009
  • 5
  • 29
  • 51

1 Answers1

0

I fixed it using the following property

<configuration>
   <systemProperties>
     <systemProperty>
        <key>org.mortbay.jetty.webapp.parentLoaderPriority</key>
        <value>true</value>
      </systemProperty>
    </systemProperties>
 </configuration>
Coen Damen
  • 2,009
  • 5
  • 29
  • 51