[WIP] Ant - quick debugging! (Linux only for now)

Discussion in 'Resources' started by nickguletskii, Mar 7, 2011.

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

    nickguletskii

    Aren't you annoyed that you have to do a ton of things manually just to test your plugin? Well, say bye bye to that!

    I have decided to start making an ant buildfile to compile, export and debug(well, not debug, but test) your plugin!

    Little tutorial:
    Start off with a normal bukkit plugin project in eclipse. Make a file in the root called "build.xml". Paste this into it:
    Code:
    <project name="simpleCompile" default="run" basedir=".">
        <target name="init">
            <property name="launcher" value="run.sh" />
            <property name="sourceDir" value="src" />
            <property name="outputDir" value="bin" />
            <property name="libdir" value="lib/" />
            <property name="jarname" value="Puzzler" />
            <property name="config" value="config/" />
            <property name="dist" value="bukkit/server" />
        </target>
        <target name="clean" depends="init">
            <deltree dir="${outputDir}" />
        </target>
        <target name="prepare" depends="clean">
            <mkdir dir="${outputDir}" />
        </target>
        <target name="compile" depends="prepare">
            <javac destdir="${outputDir}">
                <src path="${sourceDir}"/>
                <classpath>
                    <fileset dir="${libdir}">
                        <include name="*.jar" />
                    </fileset>
                </classpath>
            </javac>
        </target>
        <target name="deploy" depends="compile,init">
              <zip destfile="${dist}/plugins/${jarname}.jar">
                <fileset dir="${outputDir}"/>
                <fileset dir="${config}"/>
              </zip>
        </target>
        <target name="run" depends="deploy">
            <exec executable="bash">
              <arg line="${launcher}"/>
            </exec>
        </target>
    </project>
    Change property "jarname" to the name of your plugin. Make another file called "run.sh". Paste this inside it:
    Code:
    cd bukkit/server/
    xterm -e java -jar craftbukkit.jar
    Note: gnome users can change xterm -e to gnome-terminal -x
    Create the following folders in the root of the project: bukkit, lib, config. To the "bukkit" folder add a folder called "server", and paste craftbukkit jar into it (NOTE: rename the craftbukkit-snapshotwhateverthelongnameis.jar to craftbukkit.jar). Now go to the lib folder. This is where you should place all the libraries in, like bukkit.jar. Then, proceed to the config folder. "plugin.yml" goes there. Add a folder called "META-INF", and put your manifest into it.

    Okay, that part is done. Now you need to add the buildfile to launch configurations. In Eclipse, click on that run icon with a little toolbox in the corner. Then, click "External Tools Configurations...". Double-click "Ant Build" in the list. In the "Main" tab, Buildfile component group, click on "Browse Workspace" and select the buildfile. Finally, click on "Apply" and "Run".

    It should now work!
     
    Visagalis likes this.
  2. Offline

    Visagalis

    thanks mate! It helped me alot!
     
  3. Offline

    nickguletskii

    No problem! Also, you might want to use gnome-terminal -e instead of xterm!
     
  4. Offline

    Cartan12

    In Netbeans, it's pretty simple.
    If you want a copy to your plugins folder, you only have to add

    Code:
    <target name="-post-jar">
            <copy file="${dist.jar}" flatten="true" todir="C:/an/absollute/path" />
            <copy file="${dist.jar}" flatten="true" todir="../a/relative/path/server/plugins/" />
        </target>
    below
    Code:
    <import file="nbproject/build-impl.xml"/>
    in your build.xml.
    Then just press build, and start your server.

    For the "MANIFEST.MF ", you have to add
    Code:
    manifest.file=manifest.mf
    to your project.properties in the nbproject folder.
    The "MANIFEST.MF" should be in the same folder as the build.xml
    In the MANIFEST.MF you can set the classpath to the sqlite.jar or something like this.

    For example:
    Code:
    Manifest-Version: 1.0
    Class-Path: ../lib/sqlite.jar
    P.S.:
    You can use it with all OS i think (tested with Ubuntu and Windows)
     
  5. Offline

    nickguletskii

    It shouldn't run on Windows because it uses xterm or gnome-terminal to launch the server in a different window.
     
  6. Offline

    Cartan12

    ???
    It's for Netbeans and you don't have to use xterm or gnome-terminal...
     
  7. Offline

    Favorlock

    If you're a windows user you change "bash" to "cmd" and it will build successfully. I do receive one error, but I'm still playing around with it to meet my needs.

    I fixed a few issues with some slight modifactions:
    Code:
    <project name="simpleCompile" default="run" basedir=".">
        <target name="init">
            <property name="launcher" value="run.sh" />
            <property name="sourceDir" value="src" />
            <property name="outputDir" value="bin" />
            <property name="libdir" value="lib/" />
            <property name="jarname" value="Puzzler" />
            <property name="config" value="config/" />
            <property name="dist" value="bukkit/server" />
        </target>
        <target name="clean" depends="init">
            <delete dir="${outputDir}" />
        </target>
        <target name="prepare" depends="clean">
            <mkdir dir="${outputDir}" />
        </target>
        <target name="compile" depends="prepare">
            <javac includeantruntime="false" destdir="${outputDir}">
                <src path="${sourceDir}"/>
                <classpath>
                    <fileset dir="${libdir}">
                        <include name="*.jar" />
                    </fileset>
                </classpath>
            </javac>
        </target>
        <target name="deploy" depends="compile,init">
              <zip destfile="${dist}/plugins/${jarname}.jar">
                <fileset dir="${outputDir}"/>
                <fileset dir="${config}"/>
              </zip>
        </target>
        <target name="run" depends="deploy">
            <exec executable="cmd">
              <arg line="${launcher}"/>
            </exec>
        </target>
    </project>
     
Thread Status:
Not open for further replies.

Share This Page