Proper way to "require" another plugin.

Discussion in 'Plugin Development' started by Bugz, Sep 3, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Bugz

    Hello,

    I am brand new to Java and Eclipse, and I have been trying to figure out how I properly include another plugin as a dependency in my plugin.

    My goal is to use certain functions from the Bukkit plugins WorldBorder and WorldEdit, specifically fetching information these plugins generate.

    Now, I have added the jar's to my main folder with pom.xml, and I have added the following to my pom.xml, now, not only does it not work, I have also understood this is not the proper way to do it.

    POM.XML
    <dependencies>
    <dependency>
    <groupId>org.spigotmc</groupId>
    <artifactId>spigot-api</artifactId>
    <!-- Bukkit API Version, change if out dated -->
    <version>1.10-R0.1-SNAPSHOT</version>
    <scope>provided</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>com.sk89q</groupId>
    <artifactId>WorldGuard</artifactId>
    <version>6.2.1</version>
    <scope>system</scope>
    <systemPath>${basedir}/worldguard-6.2.1.jar</systemPath>
    </dependency>
    <dependency>
    <groupId>com.wimbli</groupId>
    <artifactId>WorldBorder</artifactId>
    <version>1.8.7</version>
    <scope>system</scope>
    <systemPath>${basedir}/worldborder-1.8.7.jar</systemPath>
    </dependency>
    </dependencies>


    Why won't this work? And what exactly is the proper way to include plugins? Eclipse spits out the following error on install.

    Eclipse error
    [37,17] error: package com.wimbli does not exist

    I try and import WorldBorder in my file by writing
    import com.wimbli.WorldBorder;
     
  2. Offline

    Reflxction

    In your plugin.yml, if your plugin requires another plugin to work, you do that:
    Code:
    depend: [WorldBorder]
    However, if the plugin does not need it, but a single optional feature in your plugin does, add it like this:
    Code:
    softdepend: [WorldBorder]
    And you don't need to import the package of the plugin you need, you only import it if you are going to use it in your code
     
    MasterDoctor likes this.
  3. Offline

    Bugz

    Hello,

    Thank you for the reply. I already have the depend in my plugin.yml, tho, it doesn't work? How exactly would i access the GetWorldBorder function in the WorldBorder plugin located at https://github.com/Brettflan/WorldB.../java/com/wimbli/WorldBorder/WorldBorder.java within my plugin?
     
  4. Offline

    Caderape2

    @Bugz Since the plugin you need is loaded by bukkit, you just have to add the depend in your plugin.yml and add the plugin to your buildpath. Then you create an access in your onEnable.
     
  5. Offline

    Bugz

    Hello,

    Thank you for the reply, care to explain how I add the plugin to my "buildpath" ?

    Edit: I'm pretty sure i managed to add it to my build path by right clicking the project -> Properties -> Java Build Path -> select Maven dependencies.

    I see WorldBorder and WorldGuard in dependency list, but i'm still getting the following error on compile when trying to include

    WorldEditPlugin wep = ....

    The errors i get are now.
    error: cannot find symbol
    [ERROR] symbol: class WorldBorder
    [ERROR] location: class MineJSONPlugin
     
    Last edited: Sep 3, 2017
  6. Offline

    AlvinB

    @Bugz
    Have you tried running mvn install or mvn clean install? Maven might not automatically load those dependencies which aren't from the local repository.

    Also, having things on disk is exactly the opposite way maven was designed to work. What you should do is find maven repositories for these plugins and fetch them from there, instead of trying to have them be loaded locally.
     
  7. Offline

    Bugz

    @AlvinB Yes, MVN install is what i always run it as, i havn't figured out any other way to run it. Still doesn't work, same errors.

    How Maven was designed to work I have no clue about, I'm not asking for psuedo-code on how to do things here, Google is riddled with these answers already. I'm looking for exact, 100% accurate, code specific examples on how things work.
     
  8. Offline

    Caderape2

    @Bugz You don't need maven.
    - Right Click on your project > build path > configure build path > librairies > add external jar
    - Add like this wordedit or another plugin you want to use
    - Add the depend in the plugin.yml
    - Create an access in your onEnable

    - Define the variable 'wep' as a field for access it outside of the onEnable method
     
  9. Offline

    Bugz

    Hello @Caderape2,

    That's exactly what I was doing from your first post. But it's still not working. Currently it looks like this.

    Build path
    [​IMG]

    It fetches from the pom.xml dependencies here, where it's defined as scope system with systemPath to the jar. I also tried the direct way, "Add external libraries", it yields the same result, same errors.

    Plugin.yml
    [​IMG]

    .java file
    [​IMG]

    Error
    [​IMG]
     
  10. Offline

    MasterDoctor

    If you're adding dependencies, you need to add it to maven, not your IDE's Java Build Path.
    If you don't want it in your plugin you just need to set the scope as 'provided' (this is what you want here by the way.)

    No actually if it's a maven project he does need to add the dependency to maven otherwise mvn install won't work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  11. Offline

    Bugz

    Hello,

    I appreciate the reply, but your really not helping. My query for this specific thing already pops up as the first result on Google for this specific topic, which only proves how extremely little and un-documented this is. I have no clue where to start to get started with Bukkit development.

    I need specifics, do this, write that, etc. Psudo code, which so many people already has explained this with, doesn't work unless your talking to someone with years of experience with the language.

    I have over a decade experience with programming and work as a full time system developer, but this is my first time ducking into Java and Bukkit, and regardless of how fluent i know PHP, JS, Node, Pawn, CSS etc, i'm at a loss. Not a single place, document or person has yet been able to describe the process of including and using another plugin in Bukkit, that I, as a developer with 16 years experience, can understand without asking questions.

    I knew Java was crap before I headed into this, but I refuse to believe it's this complicated and messy.

    PS: I have no real clue what Maven is or what alternatives exists, i forked a very very small pre-existing Bukkit plugin that i'm wanting and trying to extend into doing more, and that more requires access to other plugins.

    I have no interest in including the plugin within my plugin ( I believe you refer to this as shading ), i want my plugin to work all on it's own where the third-party plugin functionality can be enabled in the config file. IF the user choses to enable functionality from a third party plugin, i want them to install it, as a requirement, instead of the third party plugin being a part of my plugin completely.
     
    Last edited: Sep 5, 2017
  12. Offline

    Horsey

    It is VERY well documented, here's what came up: https://stackoverflow.com/questions/9164893/how-do-i-add-a-maven-dependency-in-eclipse
    There is absolutely no code in Maven, idk unless you're considering XML as coding?
    irrelevant...
    That is an EXTREMELY subjective statement.
    sigh... Why have you come here if you don't even know how to compile a JAR? There's the default jar.exe Java compiler, with that, you don't need to have a pom.xml. And there's Gradle, which is sorta like Maven.
    Okay..?


    Now, your actual problem was stated, quite clearly, by eclipse: it cannot find your JAR at the systemPath specified.[/quote][/QUOTE]
     
    Last edited: Sep 7, 2017
    MasterDoctor likes this.
  13. Offline

    AlvinB

    This is not correct. It clearly says in the libraries screenshot that it has found both the worldguard jar and the worldborder jar (Although not through maven, OP seems to have added them manually).

    @Bugz
    The problem here is what I said earlier about maven not being designed to reference system libs directly. Maven is a tool to compile Java source code, and it it supposed to manage dependencies without having to reference jars. It instead prefers to download code from online repositories, and have them installed to your local repository (the m2 directory in your user folder) and then reference them from there. Referencing a jar directly on disk using <systemPath> is deprecated and doesn't work properly (as shown here). If you have to use a jar that doesn't have an online repository, maven prefers you to install it into the maven repository using the maven install plugin (see this SO answer).

    Honestly, I think maven might just be complicating things for you. It will probably be easier to just use the compiling functionality built in to your IDE (IE eclipse).
     
    Bugz likes this.
  14. Offline

    Horsey

    do this, sorry for misreading the problem.
     
    MasterDoctor and AlvinB like this.
  15. Offline

    Bugz

    @Horsey Thanks for trying to be "tough, telling me the lay of the land, failing miserably in the process. Except for giving me a slightly (Read: Slightly) better insight on how Maven works, then your entire response was completely useless and a total waste of time.

    Thank you so much for this reply, i've used systemPath all the time, in the pom.xml file along with adding the dependencies as external JARs in the build path as i've been told earlier. None of it has worked, and i have not been able to test the "repo" solution because the plugin i want to use (Worldborder) doesn't have an online repository (Not that I can find at least).

    Appreciate the patience, I am now one step further in comprehending what's going on here :)
     
  16. Offline

    AlvinB

    @Bugz
    Alright. I think it will just be simpler to just not use maven for the time being (it is possible to install local jars into the maven repository, but it's rather complicated), and just use the compiling functionality built in to your IDE.
     
  17. Offline

    MasterDoctor

    Both Maven and Bukkit are far from undocumented and I found sufficient resources going into it not knowing anything about programming let alone Java/Maven.
    Searching 'bukkit development guide' gets me Bukkit's own documentation on how to get started: https://bukkit.gamepedia.com/Plugin_Tutorial

    You can search for video tutorials and exercises - one that's largely recommended is Pogo: https://www.youtube.com/playlist?list=PLAF3anQEEkzREsHA8yZzVhc3_GHcPnqxR
    He has 87 episodes on doing certain tasks in Bukkit.
    Something I recommend you do is find the Bukkit Javadoc (Javadoc is API documentation that is automatically generated for Java projects) and look at how the methods there correlate to other's use of them - this will get you used to reading Javadocs which will help you a lot.

    If you want to go more in-depth, I suggest you find someone offering personal programming lessons and ask them to give and review tasks.

    If you still can't find anything, let me know, I'll make a video tutorial.

    That's not helpful especially on a forums for software written in Java.

    Maven is essentially a tool to assist in building your project. I believe you would generally use it if you were on a team or working with a large project.
    You can get more information here: https://maven.apache.org/what-is-maven.html
    Note: You do not have to use Maven, you can simply create a Java project and import your dependency as a library.

    Alternatives (if you are just using it for dependency management - which it seems you are doing) are Ant/Ivy and Gradle.

    Yes but you still have to compile against the libraries.
     
Thread Status:
Not open for further replies.

Share This Page