javac returns "error: module not found: ini4j"

Head Geek :

I've got a small program (presently six *.java files, plus the ini4j-0.5.4.jar library). It works fine from Eclipse, but I need to compile and run it on a system with no graphics capability, so I've built a javac command for it, to be run from the project directory:

javac -d bin -classpath libs/ini4j-0.5.4.jar src/main/*.java

When it runs, it produces two lines:

error: module not found: ini4j
1 error

I've been away from Java programming for some years, and I'm just catching up with the changes for modules and such. It seems that that's the source of the trouble: the ini4j file was written before modules were a thing. I've seen hints that there's a way to make a modular Java program work with non-modular components, and obviously it works when I run it from the Eclipse GUI, but the way to coax the javac compiler to accept it eludes me.

I'm using openjdk (and javac) 11.0.3 under Ubuntu 19.04, if that helps.

Bottom line: how can I get this non-modular JAR file to compile into a new (modular, simple) Java program with the javac command-line compiler?


SOLUTION: With the help of the comments and answer, I found a way to fix the problem, by altering the javac command line to this:

javac -g -d bin --module-path libs/ini4j-0.5.4.jar src/main/*.java

Now it doesn't give me any problems when compiling. :-) Still trying to figure out how to actually run it from the command line, but that's a different subject.

Thank you all for your help!

Mikhail Kholodkov :

The answer is given here in the comments section - Error: automatic module cannot be used with jlink: - Maven with JavaFX

The unfortunate thing about jlink is it can only create images when everything is an explicit module (i.e. has a module-info file). At least one of your dependencies (ini4j) is not an explicit module; see What is an automatic module? for more information. You have at least a few options:

(1) Modify/fork the dependency to be an explicit module,

(2) fallback to the classpath and package your application in a "fat" jar

(3) try jpackage (early-access, I doubt javafx-maven-plugin provides support yet)

Personally, I'd recommend to go with option #2. Use any appropriate maven/gradle plugin to package your app as an executable JAR. It'll be easier to deal with the app and its dependencies now and later.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=155631&siteId=1