powered by Jive Software

Trouble with xpp3 and Java/Jigsaw modules


#1

I’m trying to use Smack 4.4.0-alpha1 but this applies to older versions too.

When compiling using Java 11 (and I guess from 9 and later) I get this compilation error

Error:java: the unnamed module reads package javax.xml.namespace from both java.xml and xpp3

This is because the xpp3 JAR includes the javax.xml.namespace.QName class. Something that has been a problem since java 1.5 which included that class in the JDK. Mostly it’s been passing under the radar since the classloader has just picked one of them but with a module path this is stricter.

The XPP3 maintainer has an issue in his Jira since 2017 (https://github.com/aslom/xpp3/issues/2) but does not seem to make any progress.

I’ve tried to exclude the XPP3 and use kxml2 instead but that has other problems and is not usable with Jigsaw modules.

If anyone knows of a work-around I’d be happy because I’m sort of stuck.


#2

Looks like it is time to start working on SMACK-591. I should probably consider scheduling this issue for Smack 4.4.

I am not sure that this is the offical home of XPP3. But anyway, I would not expect any further progress of XPP3.


#3

I am not sure that this is the offical home of XPP3.

I think it’s the closest you can get, Aleksander Slominski is the original author of XPP and worked together with, among others, Stefan Haustein (the kxml author) on JSR 173 - StAX (completed around 2004)

I’m not sure how easy it is to make a single Smack jar that’s compatible with both Java 9+ and Android. I’m not an Android developer but as I understand it Google didn’t include the StAX API on Android since they decided to use XmlPullParser instead. I’ve heard that historically there have been issues including the StAX API on Android (https://github.com/FasterXML/jackson-dataformat-xml/issues/142) but maybe that’s history these days. I certainly hope so.


#4

Not sure, if it’s feasible, but there’s a similar artifact “xpp5”, which includes most classes from org.xmlpull.v1, but lacks the javax package.

However, it also lacks the MXParser class, or rather has it in another package.

<dependency>
  <groupId>org.ogce</groupId>
  <artifactId>xpp5</artifactId>
  <version>1.2.8</version>
</dependency>

But Smack could probably just use a Provider for different implementations!?

Alternatively you could try it with shade plugin, if you are using Maven:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>xpp3:xpp3</artifact>
                                <excludes>
                                    <exclude>javax/**</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>