Debug Minecraft plugin in an IDE

Discussion in 'Spigot Plugin Development' started by Swords123456, Jun 3, 2018.

  1. in the .bat or .sh that you have running your server add this in between java and -jar
    Code (Text):
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
    Then run the server and you will see it is opening a dt_socket on port 5005. This shows its working. Im guessing your using IntelliJ

    So just run the debug configuration and whenever the plugin runs over a breakpoint in your code it will stop the server and let you look at everything.

    I use eclipse so i'm not sure exactly how it works in IntelliJ
     
  2. sorry for the late reply. the issue is that once it was connected. The plugin doesn't show when doing /plugins. And anything in the plugins isnt working. Am i doing something wrong?
     
    #3 Swords123456, Jun 3, 2018
    Last edited: Jun 3, 2018
  3. This could be down to a missing dependency. If it's a public plugin head over to their download page and check for any other plugins that it requires. If it's your plugin it shoulds like you're plugin.yml file is broken so double check there.
     
  4. Both of these tutorials are over complicated, here's a simpler one (%% = project root):

    Make a new folder called spigot, or server in %%.
    Put your spigot jar inside the folder
    In the top right corner, there should be a drop down, click that then click the option "Edit Configurations..." upload_2018-6-3_19-12-2.png
    In the window that opens, press the + and select Jar Application.
    upload_2018-6-3_19-13-4.png
    Give the configuration a name
    For path to jar, link to the spigot jar we added into %%/spigot/ a minute ago
    Working directory is the folder your spigot jar is in
    Save the configuration
    In the dropdown, select the new configuration you made, then press the debug button (you'll need to accept the eula)
    upload_2018-6-3_19-15-19.png

    Note, for this setup to work, you'll need to setup your buildtools to output the jar into your servers plugin folder. The intellij debugger does support hotswapping (run > reload changed classes), which allows you to automatically update your code without restarting the server, but it's very limited. I suggest setting up dcevm & hotswap agent for nearly unlimited hotswapping abilities. https://zeroturnaround.com/software/jrebel/ is also an option, but it's very expensive, the previous option is free.


    Buildtools setup:
    Gradle:
    Add this somewhere in your build.gradle:
    Code (Text):
    tasks.withType(Jar) {
        destinationDir = file("$rootDir/spigot/plugins")
    }
    Maven:
    Add this somewhere in your pom.xml
    Code (Text):
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.1.0</version>
          <configuration>
            <outputDirectory>${basedir}/spigot/plugins</outputDirectory>
          </configuration>
        </plugin>
      </plugins>
    </build>
    Intellij Build Artifacts:
    upload_2018-6-3_19-27-52.png
     
    #5 PiggyPiglet, Jun 3, 2018
    Last edited: Jun 3, 2018
  5. No i know it is not the plugin, because it works for an external server
     
  6. I am so close... in tried to install dcevm, but i got an error, i know that is a jdk. but it doesent say so
    Edit: nvm fixed it thank!
    Code (Text):
    java.lang.IllegalArgumentException: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk is no JRE or JDK-directory.
        at com.github.dcevm.installer.Installation.<init>(Installation.java:68)
        at com.github.dcevm.installer.AddDirectoryAction.actionPerformed(AddDirectoryAction.java:66)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6533)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
        at java.awt.Component.processEvent(Component.java:6298)
        at java.awt.Container.processEvent(Container.java:2237)
        at java.awt.Component.dispatchEventImpl(Component.java:4889)
        at java.awt.Container.dispatchEventImpl(Container.java:2295)
        at java.awt.Component.dispatchEvent(Component.java:4711)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
        at java.awt.Container.dispatchEventImpl(Container.java:2281)
        at java.awt.Window.dispatchEventImpl(Window.java:2746)
        at java.awt.Component.dispatchEvent(Component.java:4711)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
        at java.awt.EventQueue$4.run(EventQueue.java:731)
        at java.awt.EventQueue$4.run(EventQueue.java:729)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
     
    #7 Swords123456, Jun 3, 2018
    Last edited: Jun 3, 2018