How to include Apache Commons IO

Discussion in 'Spigot Plugin Development' started by Jaume, May 6, 2017.

  1. How can I include the Apache Commons IO library in my plugin? I've read in the bukkit forums to include it in my jar, but I don't know how. Is it possible? I already know how to add it as an external JAR in eclipse.
     
  2. I would suggest using Maven for dependency managment
     
    • Agree Agree x 1
    • Winner Winner x 1
  3. Use either maven or gradle to do this.

    Maven:
    Code (XML):
    <dependencies>
        <dependency>
            <artifactId>commons-io</artifactId>
            <groupId>commons-io</groupId>
            <scope>compile</scope>
            <version>2.5</version>
        </dependency>
    </dependencies>

    <build></plugins>
    <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.0.0</version>
    </plugin>
    </plugins></build>
    Gradle:
    Code (Groovy):
    repositories {
        mavenCentral()
    }

    dependencies {
        compile 'commons-io:commons-io:2.5'
    }
     
  4. How would I have to do it? Assume I have no previous experience working with Maven.
     
  5. How to do it? As I just said, I have no prior experience in this stuff. I think we posted at the same time.

    EDIT: I see there's lot of information on the Internet. I'm OK for now, I'll bump if I need to. Thanks!
     
    #5 Jaume, May 6, 2017
    Last edited: May 6, 2017
  6. If you use Eclipse, I cannot help, as last time I properly used Eclipse was at least 4 years ago.
    If you use IntelliJ, you'd just add it as a framework.
     
    • Like Like x 1
  7. OK so I'm now trying to figure out how to properly write my pom.xml file. Any help? :D

    EDIT: I want apache commons io and spigot as dependencies.
     
  8. Last time I used eclipse maven and git was a mess.

    @topic I recommend switching to intelliJ idea.
     
    • Agree Agree x 1
  9. Ok so now I have the Apache Commons IO library working thanks to Maven. However, Eclipse does not recognize classes from the plugin project itself. It shows the usual quick fix (import me.jabamun01. etc etc) but it does nothing as the import is already there and not working. I've tried to restart Eclipse.

    EDIT: Looks like it's fixed, the package declaration was missing or something. Anyway, when extracting through maven build it says it will create an empty jar because "no content was marked for inclusion". What does that mean?
    My pom.xml i got form a template:
    Code (Text):
    <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>me.jabamun01</groupId>
    <artifactId>pvz</artifactId>
    <version>0.1</version>
    <name>PvZ</name>
    <description>A Plants Vs Zombies Spigot plugin</description>

    <properties>
        <!-- Removes warnings -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Used in plugin.yml -->
        <mainClass>PlantsVsZombies</mainClass>
        <!-- Also used in plugin.yml -->
        <author>jabamun01</author>
    </properties>
    <build>
        <!-- Uses the properties in this file for plugin.yml and config.yml -->
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>plugin.yml</include>
                    <include>config.yml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <!-- Sets the Java version to 8 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <!-- Sets the custom JARfile name (Project name without spaces is good) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <finalName>${project.name}</finalName>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- This is the spigot repository, if you need others look them up -->
    <repositories>
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
    </repositories>
    <!-- Spigot dependency version, if you need others look them up -->
    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.10.2-R0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <artifactId>commons-io</artifactId>
            <groupId>commons-io</groupId>
            <scope>compile</scope>
            <version>2.5</version>
        </dependency>
    </dependencies>
    </project>

     
     
    #9 Jaume, May 6, 2017
    Last edited: May 6, 2017