Issue
I want to code a 1.18.2 Minecraft plugin using Java in the eclipse IDE. I'm pretty sure I'm using the latest versions for everything. I'm using a tutorial and when it said to put this in:
public class Main extends JavaPlugin {
A red line shows up under JavaPlugin and it says it cannot be resolved to a type. I'm supposed to import this:
import org.bukkit.plugin.java.JavaPlugin;
Everything I've googled has said to put the spigot jar in project properties > build path > libraries > add external jar which I've done, but it still doesn't work.
Solution
It's better to use platform like maven or gradle. Since Spigot 1.17 (include) it's not so easy to use spigot build as build path library.
In detail of all possibilities:
- Use direct file. It's not recommended.
Since 1.17 included, the spigot jar contains others jar, and when you run the server, it copy all of them into folders. So, each files are containing part of the full spigot code :
bundler/libraries
contains all basic libraries such as what you want:spigot-api-1.18.jar
or mysql connectors.bundler/versions
contains the NMS part of spigot. Prefer to don't use this, but sometimes it's the only way to do what you want.
Those files (in the bundler
folder) can be imported in eclipse such as you do for the global spigotmc.
- Use Maven (documentation), and add this into your
pom.xml
file :
<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Now, to build your project, you can: right click on project -> Run As -> Maven build
- Use Gradle (documentation), and add this into your
build.gradle
file :
repositories {
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
// Pick only one of these and read the comment in the repositories block.
compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
}
To build your project, you should create a new task (on top, where you run basic Java project) and config it as you want. More informations
Answered By - Elikill58
Answer Checked By - David Marino (JavaFixing Volunteer)