Rajaut Baptiste Rajaut Baptiste - 1 month ago 8
Java Question

IntellIJ idea does not want to use my external library

I have a school project to build a Jar library containing a basic card management system, then use it in the main project (a blackjack game)

With IDEA I separated the modules, then I built the jar artifact. I now have all my classes in my

jar
.

The generic card management module name is named
Carte
(card in french), generated into a
Carte.jar
file

Now I add this jar as a library for the
blakcjack
module...

I did an
import Carte.*;
which give me
unresolved symbol Carte
...

Without import, I got unresolved symbol for classes from my library

How am i supposed to use my library?

enter image description here
enter image description here

Answer

It looks like the classes in your library are in the default package, i.e. they don't have a specified package name. Carte is the name of the module, but not a Java package. I marked what I mean on this screenshot.

Java doesn't allow importing classes from the default package, as per Java language specification:

It is a compile time error to import a type from the unnamed package.

So, you should avoid the default package to be able to use the classes from a library.

Another possible reason of why the classes seem to be in the default package is that you've improperly packed the jar.

Comments