Using VS Code to work on PhantomBot

PhantomBot Version: 3.0.0
OS Version: Windows 10
Java Version:
Browser and Version (for Panel Support):
Stock PhantomBot: (Yes)/No (Yes if you have not modified the scripts or Java Core)

Hi, VS Code is mentioned as a development platform in two different posts:
Developing using vs code @LordTyrius says he managed to get it working.
Modifying a Stock PhantomBot Module

I’d really like to use VSCode, and build out the DEVSETUP.md with instructions on how to setup VS Code, but I can’t figure out how to get it working. I have modified no files so far, except DEVSETUP.md. It’s entirely possible that I haven’t set up a Java Project yet. When I try to create a Java Project, it asks me what folder, and then adds a new Java Project inside that folder.

I’ve followed the instructions here: Writing Java with Visual Studio Code
and I’ve tried using the extensions Task Explorer and Ant Target Runner.

My most frequent error message is a series of “The import cannot be resolved” “JdbcConnectionPool cannot be resolved to a type” and other such messages.

I don’t think this will help, but here’s what my dev enviro looks like. I’m happy to provide more information.

Hey,
sadly I haven’t worked with the bot for long, as the project I was trying to use it for has struggled a lot.
Back then all I needed to do was generate eclipse-style .project/.classpath files as seen in the thread you linked.

Out of curiosity I just checked out the phantombot repo again. Master doesn’t seem to compile atm, as I get 2 seemingly legitimate errors, but when checking out a release tag all I needed to do was run the ant targets (“classpath” seems to pull dependencies, “dist” built a complete zip for me).

I am unsure how this is working, my guess would be vscode has since gotten support for ant/ivy that enables correct dependency management ootb.

If you are encountering these errors after having run the ant targets, I am afraid I can not help with this issue, as it seems to work fine for me in a fresh repo…

Best regards.

1 Like

@LordTyrius, Thank you for the suggestions! Manually adding the .project and .classpath from the first thread helped.

Now I’m seeing:

!ENTRY org.eclipse.jdt.ls.core 4 0 2020-02-04 22:49:51.801
!MESSAGE Error occured while building workspace. Details: 
 message: Project 'PhantomBot' is missing required library: 'libraries/Discord4J-2.9-shaded.jar'; code: 964; resource: C:/Users/racha/Code/PhantomBot;
 message: The project cannot be built until build path errors are resolved; code: 0; resource: C:/Users/racha/Code/PhantomBot;

Is that the same legitimate error you saw? I checked out the v3.0.0 tag and confirmed using git log that the last update was Mar 4th.

I don’t even have a ‘classpath’ ant target. :frowning: I really want to muck around with greetings, and maybe see if I can get song requests to work with spotify, or at least limit them to no copyright music on youtube. Being blocked on setup though is a real bummer.

I appreciate you taking the time to reply.

Nevermind that last error. I realized the version in the classpath didn’t match the version in libraries, so I updated the classpath file. Now I’m stuck in “cannot be resolved” hell again. :upside_down_face:

Hang in there, I think I got you.

First of all, what imports are failing? I checked out v3.0.0 (which is what you are working with?) and libraries there have changed from when that old .classpath file was created. For example in “PhantomBot.java” the first import that fails for me was “net.engio.mbassy.listener.Handler”, which I guess comes from “mbassador-1.3.1.jar” which is not present in that classpath file as posted in the other thread.

If you want to go that route make sure to double check all libraries you need are in there (at the right versions).

I never thought that approach was particularly elegant.
Something else that worked for me was using the extension “Java Dependency Viewer” by Microsoft.

After installing you have another menu in your explorer. It adds an overview of classes/packages of the project, as well as JRE system libraries. Most import though there is also “Referenced Libraries”.

You will however notice that the latter is empty for now. Click the “+” icon and select the phantombot folder. This will add something along the following lines to your .vscode/settings.json:

"java.project.referencedLibraries": [
        "lib/**/*.jar",
        "/home/{NOTE: FULL PATH REDACTED}/PhantomBot/**/*.jar"
]

Which means any .jar anywhere in the phantombot folder or subdirectories will be added to referenced libraries. You can of course import only the libraries folder by changing the path here, but the GUI wouldn’t let me select a folder without subdirectories by default.

"java.project.referencedLibraries": [
        "/home/{...}/PhantomBot/libraries/*.jar"
]

^ This should be all you need (and given the default entry, relative paths would work even better!).

After that I had no more errors show. All imports worked.

Let me know how it goes for you :slight_smile: Good luck.

It seems to me that the current master working without any settings is also because of this extension:
The jars in master reside in “lib” instead of “libraries”. Jars in this common default folder seem to be referenced automatically.

@ChaelCodes let me know if you are still trying/having trouble. If this last approach works for you too I might shoot a MR against devsetup with a notice for vscode, because it is the approach that seems most integrated right now (no need to create project files by hand or copy and adapt them).