Hey guys, I’m having some issues with trying to even start a Java project. I know I’ve created Java projects in Android Studio before, but there seems to be some really strange issues going on with why Java won’t recognize my packages I download from the internet.
So I go and create a completely clean new Java project in Intellij. I choose Java as the language and then choose Intellij as the build system. At this point, I’ve already tried all 3 build systems; Intellij, Maven, and Gradle and all 3 have this same issue I’m going to explain. I also choose JDK 18 since that’s the latest one I’ve downloaded.
After the project is successfully created, I go and create my first file under the src
folder. I name it something like HelloWorld and I see HelloWorld.java in the folder list. I then download this Java file I got from Github and place it in my src
folder. Then I do a import com.github.mrebhan.crogamp.cli.TableList;
in my HelloWorld.java file. I resolve the issue with the Github Java file not being in the right spot by moving it appropriately using the options the light bulb gives me.
Next I instantiate the class and assign a variable to it and call the methods from that class. Next I do a Build → Build Project. Project successfully builds with no errors. Open the terminal in Intellij and cd to that src
folder. Then I run java HelloWorld.java
and then I get these errors
HelloWorld.java:6: error: package com.github.mrebhan.crogamp.cli does not exist
import com.github.mrebhan.crogamp.cli.TableList;
^
Even though the package exists in my project, it still continues to throw me this error. This isn’t just the only library it does this to either. So I get the package __ does not exist
error even when installing packages from the Maven library that’s default to Intellij.
I’ve already done a File → Invalidate Cache and then rebuilding the project after Intellij restarts. That didn’t work. I’ve also tried installing Intellij on Windows (I’m currently using macOS as my main driver) machine and doing the same steps thinking maybe it’s a macOS issue and I still get the same error.
So does anyone know why this is happening and how I can fix this? I’ve tried every single possible way to just “include” an external file in my project.
EDIT: For the Maven libraries (repositories), I do File → Project Structure → Libraries on the left side → + sign to add a new library → From Maven (from that dropdown menu) → search for the library I want → Select only Transitive dependencies since that was the default (I’ve already tried every other checkboxes as well) → Click Ok → Choose my project the library will be downloaded to → Click Ok → Click Apply → Click Ok
Then I do the whole import blah.package.blah;
, instantiate the class, select the method from that class, and then rebuild project with no errors and run java HelloWorld.java
in the terminal again and still I get the package __ does not exist
error even on the new Maven library that gets added instead of downloading files from Github and importing it that way.