DEV Community

loading...

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

baenencalin profile image Calin Baenen ・1 min read

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

Discussion

pic
Editor guide
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
baenencalin profile image
Calin Baenen Author

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
baenencalin profile image
Calin Baenen Author

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

Collapse
baenencalin profile image
Calin Baenen Author

What's Maven and Gradle? Huh?

Collapse