2

I'm trying to run a project someone else made. I added the project to eclipse and it automatically generated a module-info.java and I'm getting warnings because the modules are name based, so I'm assuming this may be my issue. I am not familiar with Modules and I'm having a hard time understanding some of the resources online. Heres my runtime error.

Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\under\Desktop\RSPS\Emerald\Server\lib\xpp3.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer not in module

Here is my module-info.java

/**
  * 
  */
/**
 * @author GameBeast
 *
 */
module server {
exports com.elvarg;
exports com.elvarg.net.packet;
exports com.elvarg.world.model.teleportation;
exports com.elvarg.world.model.dialogue;
exports com.elvarg.util;
exports com.elvarg.world.content.skills.Prayer;
exports com.elvarg.world.content.skills.Herblore;
exports fileserver.net;
exports com.elvarg.world.model.container;
exports fileserver.net.codec;
exports fileserver;
exports com.elvarg.world.entity.combat.method.impl.npcs;
exports com.elvarg.world.entity.impl.npc.bots;
exports com.elvarg.world.entity.impl.npc;
exports com.elvarg.world.collision.buffer;
exports com.elvarg.world.content;
exports com.elvarg.world.model.container.impl;
exports com.elvarg.net.login;
exports com.elvarg.net.security;
exports com.elvarg.world.model.equipment;
exports fileserver.cache;
exports com.elvarg.world.model.syntax;
exports com.elvarg.world.entity.combat;
exports com.elvarg.world.entity.impl;
exports com.elvarg.engine;
exports com.elvarg.world.grounditems;
exports com.elvarg.world.entity.combat.method.impl.specials;
exports com.elvarg.world.entity.combat.magic;
exports com.elvarg.net.channel;
exports com.elvarg.net.packet.impl;
exports com.elvarg.net.codec;
exports com.elvarg.definitions;
exports com.elvarg.world.entity.combat.ranged;
exports com.elvarg.world.entity.combat.method;
exports com.elvarg.world.content.clan;
exports com.elvarg.world.entity.impl.player;
exports com.elvarg.engine.task;
exports com.elvarg.world.entity.combat.method.impl;
exports com.elvarg.engine.task.impl;
exports com.elvarg.world.entity.updating;
exports com.elvarg.world.entity.impl.npc.bots.impl;
exports com.elvarg.world.entity;
exports com.elvarg.world.entity.combat.hit;
exports com.elvarg.world.model.syntax.impl;
exports com.elvarg.world.collision.region;
exports com.elvarg.world.entity.impl.object;
exports com.elvarg.world.entity.combat.bountyhunter;
exports com.elvarg.net;
exports com.elvarg.world.entity.combat.formula;
exports com.elvarg.world.model.movement.path;
exports com.elvarg.world.model;
exports com.elvarg.world.model.movement;
exports com.elvarg.world;

requires bzip2;
requires gson;
requires guava;
requires java.logging;
requires java.management;
requires netty.all;
requires xpp3;  
}

My jar file (renamed to xpp3 because a resource on stackoverflow said the syntax of the file name could be an issue) contains the files that the error says isn't a module,

org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer

So my question is how do I add these to the module using eclipse?

Also, another post on stackoverflow said to make sure the build path was configured so that my libs were in my modulepath not my classpath, I made sure to do this as well. https://prnt.sc/owu9r3

I've been trying to figure this out for hours now, any help is greatly appreciated.

Naman
  • 27,789
  • 26
  • 218
  • 353
David Pace
  • 25
  • 1
  • 1
  • 7
  • What version of Eclipse are you using? – Andreas Aug 24 '19 at 05:08
  • Eclipse IDE for Java Developers Version: 2018-12 (4.10.0) Build id: 20181214-0600 – David Pace Aug 24 '19 at 05:13
  • The issue is not caused by Eclipse but by a broken JAR file (see my answer below). Independent of that, Eclipse 2018-12 (4.10) is outdated. The current Eclipse version is 2019-06 (4.12) and provides an [improved UI to configure modules](https://www.eclipse.org/eclipse/news/4.12/jdt.php#buildpath-module-dependencies). – howlger Aug 24 '19 at 11:10

2 Answers2

4

It seems the xpp3.jar file is broken:

The JAR file contains the provider-configuration file META-INF/services/org.xmlpull.v1.XmlPullParserFactory with the following content:

org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer

The two provider classes are specified as comma-separated list instead of one class per line. See Javadoc of ServiceLoader (highlighting in bold by me):

The file contains a list of fully-qualified binary names of concrete provider classes, one per line.

See also the error message: it says Provider class and not Provider classes and there is no space after the , so it names only the single class with the invalid name org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer.

The misleading error message talking about a module descriptor implies that the implementation of services specified via META-INF/services/* files (available since Java 6), has been merged with the new implementation of JPMS services specified via the module-info.java file (which are available since Java 9). This might result that in Java 9 and higher errors occur that did not occur in Java 8 and lower or that an error occurs at an earlier point in time (already when starting the application instead of when using it).

howlger
  • 31,050
  • 11
  • 59
  • 99
2

The error says "Provider class ... not in module", which makes me think it's about Service Providers. You should read "Java 9 Module Services" to learn more on that topic.

Service Providers should be listed in the module-info file using the provides keyword. Here is the example from the article:

module Provider {
    requires ServiceInterface;
    provides javax0.serviceinterface.ServiceInterface
      with javax0.serviceprovider.Provider;
}

module Consumer {
    requires ServiceInterface;
    uses javax0.serviceinterface.ServiceInterface;
}

module ServiceInterface {
    exports javax0.serviceinterface;
}

The xpp3.jar library doesn't have a module-info file, so the JVM will dynamically build one, hence the "Unable to derive module descriptor" part of the error message, but it detect an error.

My best guess at the error, is that the jar file contains a ServiceLoader file in the META-INF/services/ folder, which lists the 2 classes in the error message: org.xmlpull.mxp1.MXParser and org.xmlpull.mxp1_serializer.MXSerializer. However, the error message would seem to indicate that those classes are not actually in the jar file.

Check the content of the xpp3.jar, and check for existence of those two files. Also look in the META-INF/services/ to see if I'm guessing right.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • The jar file `xpp3.jar` does contain the two files at these paths `org\xmlpull\mxp1\MXParser` and `org\xmlpull\mxp1_serializer` the META_INF folder contains `META_INF/services/org.xmlpull.v1.XmlPullParserFactory` and its contents are `org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer` I am still reading that article, but I thought I'd reply in the meantime. – David Pace Aug 24 '19 at 07:33
  • So you did guess correctly, the ServiceLoader file is intact, but the provider files are in the jar file at their respective paths, not missing. I believe the interface for `xpp3.jar` is `XmlSerializer`, and the two Provider classes are `org.xmlpull.mxp1.MXParser` and `org.xmlpull.mxp1_serializer.MXSerializer` so should I just add `module-info.java` files to these directories in the `xpp3.jar` and leave my server module as a consumer? – David Pace Aug 24 '19 at 08:50
  • The error message does not list 2 classes but a single class with the invalid name `org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer`: see my answer. – howlger Aug 24 '19 at 11:04
  • @DavidPace So to fix it, modify the `META_INF/services/org.xmlpull.v1.XmlPullParserFactory` by removing the comma, and having the two class names on separate lines. – Andreas Aug 24 '19 at 17:42
  • Better yet, if possible, stop using XPP3 and use StAX instead. – Andreas Aug 24 '19 at 17:46