class rocks.xmpp.websocket.model.Open nor any of its super class is known to this context.

Issue #73 closed
Cory Redmond created an issue

I can't see anything wrong with the build of my project, the class exists, and is shaded by maven properly.

Here's the stacktrace when I run the app

Exception in thread "main" co.ryred.coribot.core.exceptions.FailureToConnectException: Failure to connect with XMPP_0
    at co.ryred.coribot.connectors.xmpp.XMPPConnector.connect(XMPPConnector.java:108)
    at co.ryred.coribot.boostrap.CoriBotStart.main(CoriBotStart.java:60)
Caused by: rocks.xmpp.core.XmppException: javax.xml.bind.JAXBException: class rocks.xmpp.websocket.model.Open nor any of its super class is known to this context.
    at rocks.xmpp.core.session.XmppSession.throwAsXmppExceptionIfNotNull(XmppSession.java:250)
    at rocks.xmpp.core.session.XmppClient.connect(XmppClient.java:251)
    at rocks.xmpp.core.session.XmppSession.connect(XmppSession.java:296)
    at co.ryred.coribot.connectors.xmpp.XMPPConnector.connect(XMPPConnector.java:106)
    ... 1 more
Caused by: javax.xml.bind.JAXBException: class rocks.xmpp.websocket.model.Open nor any of its super class is known to this context.
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:567)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:467)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:163)
    at rocks.xmpp.websocket.WebSocketConnection.lambda$send$0(WebSocketConnection.java:164)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Here's my POMs

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ http://ryred.co/
  ~ ace[at]ac3-servers.eu
  ~
  ~ =================================================================
  ~
  ~ Copyright (c) 2016, Cory Redmond
  ~ All rights reserved.
  ~
  ~ Redistribution and use in source and binary forms, with or without
  ~ modification, are permitted provided that the following conditions are met:
  ~
  ~ * Redistributions of source code must retain the above copyright notice, this
  ~   list of conditions and the following disclaimer.
  ~
  ~ * Redistributions in binary form must reproduce the above copyright notice,
  ~   this list of conditions and the following disclaimer in the documentation
  ~   and/or other materials provided with the distribution.
  ~
  ~ * Neither the name of CoriBot nor the names of its
  ~   contributors may be used to endorse or promote products derived from
  ~   this software without specific prior written permission.
  ~
  ~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  ~ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  ~ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  ~ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  ~ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  ~ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  ~ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  ~ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  ~ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ~ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>coribot</artifactId>
        <groupId>co.ryred</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>coribot-bootstrap</artifactId>

    <build>

        <finalName>CoriBot</finalName>

        <plugins>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>${versions.java}</source>
                    <target>${versions.java}</target>
                    <encoding>UTF-8</encoding>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>co.ryred.coribot.boostrap.CoriBotStart</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>

    </build>

    <dependencies>
        <dependency>
            <groupId>co.ryred</groupId>
            <artifactId>coribot-core</artifactId>
            <version>${version}</version>
        </dependency>
        <dependency>
            <groupId>co.ryred</groupId>
            <artifactId>coribot-connector-xmpp</artifactId>
            <version>${version}</version>
        </dependency>
    </dependencies>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ http://ryred.co/
  ~ ace[at]ac3-servers.eu
  ~
  ~ =================================================================
  ~
  ~ Copyright (c) 2016, Cory Redmond
  ~ All rights reserved.
  ~
  ~ Redistribution and use in source and binary forms, with or without
  ~ modification, are permitted provided that the following conditions are met:
  ~
  ~ * Redistributions of source code must retain the above copyright notice, this
  ~   list of conditions and the following disclaimer.
  ~
  ~ * Redistributions in binary form must reproduce the above copyright notice,
  ~   this list of conditions and the following disclaimer in the documentation
  ~   and/or other materials provided with the distribution.
  ~
  ~ * Neither the name of CoriBot nor the names of its
  ~   contributors may be used to endorse or promote products derived from
  ~   this software without specific prior written permission.
  ~
  ~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  ~ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  ~ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  ~ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  ~ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  ~ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  ~ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  ~ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  ~ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ~ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>coribot</artifactId>
        <groupId>co.ryred</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>coribot-connector-xmpp</artifactId>

    <properties>
        <versions.babbler>0.7.0-SNAPSHOT</versions.babbler>
    </properties>

    <build>

        <plugins>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>${versions.java}</source>
                    <target>${versions.java}</target>
                    <encoding>UTF-8</encoding>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>

    <dependencies>

        <!-- CoriBot, no duhh -->
        <dependency>
            <groupId>co.ryred</groupId>
            <artifactId>coribot-core</artifactId>
            <version>${version}</version>
        </dependency>

        <!-- XMPP Connector -->
        <dependency>
            <groupId>rocks.xmpp</groupId>
            <artifactId>xmpp-core</artifactId>
            <version>${versions.babbler}</version>
        </dependency>
        <dependency>
            <groupId>rocks.xmpp</groupId>
            <artifactId>xmpp-core-client</artifactId>
            <version>${versions.babbler}</version>
        </dependency>
        <dependency>
            <groupId>rocks.xmpp</groupId>
            <artifactId>xmpp-websocket</artifactId>
            <version>${versions.babbler}</version>
        </dependency>
        <dependency>
            <groupId>rocks.xmpp</groupId>
            <artifactId>xmpp-extensions-client</artifactId>
            <version>${versions.babbler}</version>
        </dependency>

    </dependencies>

</project>

Any help appreciated!

Comments (3)

  1. Christian Schudt repo owner

    Hi,

    I am not sure, what you are doing with the shade plugin here, but I've used it as well to create a "super-jar" which contains all classes from all dependencies.

    I use java.util.ServiceLoader to "collect" the classes from different jars and make them known to JAXB. Despite the class is on the classpath it's probably not recognized by JAXB because ServiceLoader works by looking up a file called rocks.xmpp.core.session.Module (the interface name) in a JAR's META-INF/services folder.

    If multiple jars get merged together into one by the shade or assembly plugin, they override each others file and only take the last one, so ServiceLoader only finds one file instead of multiple.

    It can be solved by using a transformer:

    <transformers>
        <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer">
        </transformer>
    </transformers>
    

    You can also have a look here, where I've used it:

    https://bitbucket.org/sco0ter/babbler/src/831c81dbdca29665fd637734f7f728b7955bc757/xmpp-documentation/pom.xml?at=master&fileviewer=file-view-default#pom.xml-100

    Hope it helps.

  2. Cory Redmond reporter

    Fantastic! Thanks a lot.

    It came across my mind that the meta-inf was pretty empty, guess I just passed it off as stupid, I'll keep that in mind! <3

  3. Log in to comment