DEV Community

Calin Baenen
Calin Baenen

Posted on

Java Import JSON Library Question about importing Java packages. (too long to put in title)

If I have a package called runtdeale.code in the folder RuntDeale/resources/code, could I do import runtdeale.code.libs.org.json.*; to import the JSON library, which is a package below my original package?

Filesystem:

RuntDeale:
    resources:
        textures: ...
        ...
        code:
            Main.java
            manifest.txt
            ...
            libs:
                org:
                    json:
                        /* org.json library files */
Enter fullscreen mode Exit fullscreen mode

Top comments (6)

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard

the convention in Maven/Gradle
is to put your code in src/main/runtdeale/code/libs/org/json
and then yes you can import runtdeale.code.libs.org.json.*
although star imports are not really recommanded.
Just let your IDE import on the fly what's needed

Collapse
 
calinzbaenen profile image
Calin Baenen

Import runtdeale.code.libs.org.json.* from where? Main.java?
Would that still remain in the same relative directory to the library as I have it now?

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard

imports are never relative

Which IDE are you using?

With IntelliJ IDEA Community Edition all this stuff is handled for you.

Thread Thread
 
calinzbaenen profile image
Calin Baenen

I'm using VSCode.
Also, what folder do I put the library in, then??

Collapse
 
calinzbaenen profile image
Calin Baenen

What's Maven and Gradle? Huh?

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited