[Solved] Using Maven with Bukkit/Eclipse

Discussion in 'Plugin Help/Development/Requests' started by travja, Dec 21, 2014.

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

    travja

    I'm new to Maven. I think I have everything set up how it should be, but I'm having troubles building the project. I'm using Eclipse with the M2Eclipse plugin. I've added Spigot to the build path and my other dependencies in the pom.xml.

    This is the error I'm getting http://pastebin.com/84b7MdDN

    Pom.xml (open)

    <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>MavenProject</groupId>
    <artifactId>MavenProject</artifactId>
    <version>0.1</version>

    <build>
    <finalName>${project.artifactId}</finalName>
    <sourceDirectory>${basedir}/src</sourceDirectory>
    <resources>
    <resource>
    <targetPath>.</targetPath>
    <filtering>true</filtering>
    <directory>${basedir}</directory>
    <includes>
    <include>*.yml</include>
    </includes>
    </resource>
    </resources>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
    <execution>
    <phase>package</phase>
    <goals>
    <goal>shade</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
    <dependencies>
    <dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.6.0</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP-java6</artifactId>
    <version>2.0.1</version>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>org.reflections</groupId>
    <artifactId>reflections</artifactId>
    <version>0.9.9-RC1</version>
    </dependency>
    </dependencies>
    </project>


    If you guys could point out what I've done wrong and how to fix it that would be great! Thanks guys!
     
    Last edited: Dec 22, 2014
  2. Offline

    stoneminer02

    *facepalm* Maven makes it so you don't have to do that..
    Try reloading the maven thing (Right click project > Maven > Reload/Refresh)
     
  3. Offline

    gogobebe2

    My bad. I just read the error log and it said couldn't find the api files :pPP
     
  4. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
    stoneminer02 likes this.
  5. Offline

    Lolmewn

    Please paste your pom.xml
     
  6. Offline

    travja

    Updated the main post to add the pom.xml
     
  7. Offline

    metmad22

    The whole point of Maven is to make dependencies a lot easier for new programmers. Here is a template of the one I used when I started:
    Code:
    <?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>YOUR PACKAGE NAME HERE</groupId>
        <artifactId>YOUR PLUGIN NAME HERE</artifactId>
        <version>YOUR PLUGIN VERSION</version>
    
         <repositories>
             <repository>
                 <id>bukkit-repo</id>
                 <url>http://repo.bukkit.org/content/groups/public/</url>
             </repository>
         </repositories>
    
         <dependencies>
             <dependency>
                 <groupId>org.bukkit</groupId>
                 <artifactId>bukkit</artifactId>
                 <version>1.7.9-R0.2</version>
             </dependency>
         </dependencies>
    
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </project>
    Once you use this as your pom.xml, your plugin.yml would look like this:
    Code:
    name: ${project.artifactId}
    main: 
    version: ${project.version}
    authors: 
    commands:
    permissions:
    
    Because you specified what the name of your plugin is, and what the version is in your pom.xml, Maven will automatically replace those fields with the given strings. This would be your basic Maven template to follow for your plugins.

    The site (http://repo.bukkit.org/content/groups/public/) is where Maven will take the bukkit builds and set it as your dependancy. The 1.7.9-R0.2 is the version of the latest release taken from the same site in the bukkit folder (http://repo.bukkit.org/content/groups/public/org/bukkit/bukkit/).

    I hope this helps you.

    To build the project (compile it to a .jar compatible file) you go to your maven settings, and there is a compile button somewhere. I can't help you much there, as I use IntelliJ as my IDE, and I have a Maven panel. It should be in your Maven settings.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 28, 2016
    Europia79 likes this.
  8. Offline

    travja

    I'm trying to build off of Spigot, not Bukkit, as Spigot is 1.8 compatible. I've added spigot as an external jar, not sure how I would do it through Maven, but I think that's what's causing my problems. Other than that, I think I'm doing ok.
     
  9. Offline

    metmad22

  10. Offline

    travja

    @metmad22 It builds now, and does run, but it's now 4 MB larger than it used to be. Not sure if that's how it should be or not....
     
  11. Offline

    metmad22

    Yes, It should be normal. You are using the whole spigot file as a dependency and possibly an other that I might not know of to code your work. Anyway, 4MB is not too big. As long as you are able to build and run it while it's working, everything should be fine :)

    If you have further questions, feel free to ask. Also if that was the only issue, please mark your title as [Solved].

    For others having the same problem, here is what your pom.xml should look like if you want the spigot build as your dependancy.
    Code:
    <?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>YOUR PACKAGE NAME HERE</groupId>
        <artifactId>YOUR PLUGIN NAME HERE</artifactId>
        <version>YOUR PLUGIN VERSION HERE</version>
    
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
            </repository>
        </repositories>
    
        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.8-R0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </project>
    
    Here is what your Bukkit dependancy would look like:
    Code:
    <?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>YOUR PACKAGE NAME HERE</groupId>
        <artifactId>YOUR PLUGIN NAME HERE</artifactId>
        <version>YOUR PLUGIN VERSION</version>
         <repositories>
             <repository>
                 <id>bukkit-repo</id>
                 <url>http://repo.bukkit.org/content/groups/public/</url>
             </repository>
         </repositories>
         <dependencies>
             <dependency>
                 <groupId>org.bukkit</groupId>
                 <artifactId>bukkit</artifactId>
                 <version>1.7.9-R0.2</version>
             </dependency>
         </dependencies>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </project>
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 28, 2016
Thread Status:
Not open for further replies.

Share This Page