1.16.5 I can't import ProtocolLib please help...

Discussion in 'Spigot Plugin Development' started by lukaspiderman1, Jul 13, 2021.

  1. So I'm trying to import the ProtocolLib into my eclipse project of a java plugin but it says that is not accessible.... I imported the external jar and tried to do "import com.comphenix.protocol.ProtocolLibrary;" but it says the following message: The type com.comphenix.protocol.ProtocolLibrary is not accessible

    Any help? Thanks ^^
     
  2. I don't know why some people these days are still too lazy to use Maven or Gradle...
    With Maven / Gradle you don't have those problems and it's not that complicated.
     
  3. I only made little plugins so I never used Maven / Gradle to import something. Do you have a video or something?
     
  4. If you are using IntelliJ you can right-click onto your project -> add framework support -> maven. Only thing left to do is adding the repository to your pom.xml:
    Code (Text):
    <repositories>
      <repository>
        <id>dmulloy2-repo</id>
        <url>https://repo.dmulloy2.net/repository/public/</url>
      </repository>
      <!-- And so on -->
    </repositories>
    and the dependency itself:
    Code (Text):
    <dependencies>
      <dependency>
        <groupId>com.comphenix.protocol</groupId>
        <artifactId>ProtocolLib</artifactId>
        <version>4.7.0</version>
      </dependency>
      <!-- And so on -->
    </dependencies>
    If you want to use Gradle open the terminal and execute Gradle init.
    Code (Text):
    dependencies {
       compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "4.7.0";
    }
    Code (Text):
    repositories {
        maven { url "https://repo.dmulloy2.net/repository/public/" }
    }
     
  5. I'm using Eclipse .-. I tried to search it on YouTube but all the tutorials are weird... Don't really understand them...
     
  6. Well, this is the perfect moment to switch to IntelliJ :) However, if you still want to stick to eclipse you may find this helpful.
     
  7. Personally, I don't have any videos about Maven in English, so you have to find them on your own.
    Depending on which IDE you are using, you may download the "Minecraft Development"-Plugin which has a Maven-Support, or otherwise you convert your Project via right-click on your project to a Maven Project.

    What I can do is that I'm posting a part of my old pom.xml:

    Code (Text):
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example</groupId>
        <artifactId>yourplugin</artifactId>
        <version>your-version</version>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>11</java.version>
        </properties>

        <build>
            <sourceDirectory>src/main/java</sourceDirectory>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <excludes>
                        <exclude>**/*.java</exclude>
                    </excludes>
                </resource>
            </resources>

            <pluginManagement>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                    </plugin>
                </plugins>
            </pluginManagement>

            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.2.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <artifactSet>
                            <excludes>
                                <exclude>org.jetbrains:annotations</exclude>
                                <exclude>com.google.protobuf:protobuf-java</exclude>
                            </excludes>
                        </artifactSet>
                        <finalName>${project.artifactId}</finalName>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>se.eris</groupId>
                    <artifactId>notnull-instrumenter-maven-plugin</artifactId>
                    <version>1.0.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>instrument</goal>
                                <goal>tests-instrument</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>org.jetbrains</groupId>
                            <artifactId>annotations</artifactId>
                            <version>20.1.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>


        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot</artifactId>
                <version>1.16.5-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.jetbrains</groupId>
                <artifactId>annotations</artifactId>
                <version>20.1.0</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </project>
     

    Short instructions to use Maven:
    Maven is created to build Java-Applications with dependencies and more.
    It's based on a pom.xml which contains required build information about your plugin.

    Vocabulary:
    groupId: The group-id is the ID you or your company is working with. Normally you have a package order like this: "com.example.pluginname", in that case, "com.example" is your groupId.
    artifactID: The artifact-id is mostly the name of your plugin. In that case, "pluginname" is your artifact-id
    version: The Version of your Plugin

    dependencies:
    Dependencies are other projects, that are compiled with Maven and stored anywhere in the internet. You can access them when you create a menu <dependency> in <dependencies> and enter the correct groupId, artifactId, version and scope to the dependency.
    After that you need to reload maven so maven can download those artifacts.

    You find the required information on the internet if you google: "<YourDependendyHere> maven"

    Scopes:
    Scopes decided if dependencies should be compiled and stored in your jar or not...
    - provided means that this dependency exists in runtime but should not be packaged into the jar
    - test means that this dependency should only be available when "mvn test" runs (currently not needed for your project)
    - if you want your dependency to be included in your jar, don't use a scope.


    Don't forget to run BuildTools before, Spigot need's to be in your local Maven-Repository as well

    EDIT: It seems I should make a Maven-Tutorial in an external Thread, you can make so much things with Maven
     
  8. I can still work on the same project if I switch to IntelliJ right?
     
  9. Sure thing. I used Eclipse before I switched lately to IntelliJ-Ultimate. It's so much easier to develop
     
  10. Maybe it is just me, but I doubt if I am alone in this.
    I have used Eclipse since day 1. And have tried to get into using InteliJ a few times. It just does not seem to suit me.

    When you are making fairly simple plugins which do not require depending on many other plugins. You don't need to use Maven or Gradle.
    You can just add a dependency plugin to the 'resource library', in the same way that you add the Spigot Jar.

    The main difference will occur when a 'resource library' resource needs to be updated. It just needs to be done manually.
     
  11. Well, why wouldn't you use dependency management tools or IntelliJ even for smaller projects? You create a new project, just like in eclipse and instead of having the dependencies lying around on your pc you add a few lines to your build.gradle/pom.xml. It's also easier to update to newer apis this way. IntelliJ will make your life easier, however, nobody will force you to use intellij, here is a detailed discussion about why you may consider using intellij over eclipse
     
  12. As that link states 'it is a subjective issue'.
    Climbing any hill will need some learning process, which will help you to start climbing a mountain.
    You should set your goals low and complete small tasks, before you tackle a huge task.

    It is all part of the learning process.
     
    • Agree Agree x 1
  13. Right-click the project -> build path -> configure build path -> Add external JARs. Locate the ProtocolLib jar file and add it to the project.
     
  14. When you don't want to use IntelliJ, it's ok for everyone. I am not a fan of IntelliJ-Community either. But what I can't understand is, that some people still believe, it's a smart way to have a lib folder inside your project and bind every single jar in your IDE.
    Even Eclipse can handle Maven and Gradle and there are no reasons to use that old lib folder strategy when Maven exists
     
    • Agree Agree x 1
  15. Just stick to maven, it just makes life easier in every way.
     
  16. I think there is value in doing it this way: it teaches that there are multiple layers of abstractions when it comes to compiling your plugin.
    1. The most concrete / least abstract method: Just invoke the javac and the jar tools explicitly from the commandline. Users have to supply their libraries on the classpath or modulepath using commandline options.
    2. A little abstraction: IDEs add a layer by allowing you to create 'build configurations' which are essentially just settings based on which the commandline arguments are generated when you click 'build' in your IDE.
    3. A lot of abstraction: Build tools such as Maven or Gradle add another layer by using descriptions of 'dependencies' and being able to download them from over the internet. At this level you don't have to do much manual work anymore, but if you do want to change some details, (e.g. do you use the classpath or modulepath to provide library X) then you have to dive deep into the documentation of the build tool and its plugins. It can be very frustrating to get stuck on trivia such as "How do I get the build tool to do X which is super easy to do if I didn't use this tool?". More abstraction means more loss of control.
    I don't think there is anything inherently wrong with any of these approaches. Reducing complexity or bootstrappability can be good reasons not to use a build tool.
     
    #16 Jannyboy11, Jul 14, 2021
    Last edited: Jul 14, 2021
    • Agree Agree x 1
  17. if you're working alone, this might be a simple solution. If you're working with a team, that's a bad solution...

    1. Maven uses a local repository. All you have to do is declaring dependencies that are going to be shaded in your jar or are already provided by other software (such as Spigot). They don't have to deploy dependencies in their classpath if Maven does that for you automatically. That’s much too cumbersome.
    2. Yes, IDEs support that useful feature. IDEs can also define Maven-Goals as Build-Configuration, which is much shorter.
    3. Due to different Maven-Goals, I can decide what's going to happen. Maven support's by creating JavaDoc, running Unit-Tests correctly in different scopes, building, and even deploying a new software version. That's extremely important when using CI/CD such as GitLab / Jenkins etc.
    4. Yes, but isn't it a good idea not to do this manual work anymore? Don't get me wrong, I understand your argument and I think your right (since I cannot find any good tutorial about maven for free). But does that really means, we have to do the same things we did in the past because we're having a lack of knowledge right now? I don't think so. I know Maven is hard for beginners, but it's a very powerful tool and you can do many things so much easier.
    I am keeping Gradle out of this. I don't have much experience with Gradle, I prefer Maven. Someone who uses Gradle can share his/her experience with Gradle here, too
     
  18. Yea I did that but for some reason it says that it can't be accessed .-.
     
  19. In that case I don't know dude. I haven't used eclipse anymore in years, I hopped on the IntelliJ bandwagon too. It looks like you have found yourself a bug in Eclipse.
     
  20. Where is the file located? try moving it to the same location as your source and test then. Mayby it lacks permissions for that location