Home > Software engineering >  JavaPlugin cannot be resolved to a type
JavaPlugin cannot be resolved to a type

Time:03-25

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.

CodePudding user response:

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.

You should :

  1. Convert your project into a maven/gradle one. Here you own are empty, so maybe it's easier for you to remove it and create a new project which is not basic but maven/gradle one.

You can also do it with right click on project -> Configure -> Choose what you want

  1. In dependency, add:

Maven (documentation):

<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>

Gradle (documentation):

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'
}
  1. Refresh your project. It will automatically download dependencies and build your project.

  2. To generate your jar for your plugin, you should :

Maven: right click on project -> Run As -> Maven build

Gradle: You should create a new task (on top, where you run basic Java project) and config it as you want. More informations

  • Related