Skip to content

How to add a Library in the main module [module-info.java]? #60

Closed

Description

I use the jssc package to access serial port. I added it to the main module

module DeskCheck {
  requires java.desktop;
  requires java.logging;
  requires jssc;
}

But I believe I am doing it wrong, because there is an error saying that module does not exist.

Creating jlink image in dist\jimage/.
Executing: C:\Program Files\jdk-12.0.2\bin\jlink.exe --module-path dist\DeskCheck.jar;C:\Program Files\jdk-12.0.2\jmods --add-modules DeskCheck --output dist\jimage --compress=2
Error: Module jssc not found, required by DeskCheck

Question taken from Stack Overflow in Portuguese:

https://pt.stackoverflow.com/questions/416758/como-adicionar-um-library-no-modulo-principal-module-info-java

Activity

  1. tresf commented on Oct 22, 2019

    @tresf

    I believe you need to add our jar to the launch options....

    java --module-path path/to/jssc-2.9.1.jar 

    As the stackoverflow article explains, modules are not for dependency management. Instead, they're used for modularity and can control scope and security. This article explains their purpose: https://www.baeldung.com/java-9-modularity

    We use these directives to be much more explicit about how our code is to be used.
    We could put the interface into a private package while exposing the implementation in a public package.
    This makes our code much more secure with very little extra overhead.
    Go ahead and try out some of the other directives to learn more about modules and how they work.

    This article explains how to combine modules with Maven: https://dzone.com/articles/java-9-modules-part-2-intellij-and-maven

    Alternately, you can always add the source code of JSSC into your project (e.g. as a subtree or submodule) and let your project compile the components as needed.

    If you'd like to add any steps to the wiki to make this easier for others, please let us know. Closing as I don't think there's a bug here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionSupport question, not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions