13

I'm helping my kid learn to create Minecraft plugins, although I don't have much experience with Java or IDEA. Everything is working well so far, but in order to execute our code, we have to:

  1. Make the project in IDEA (output path is set to Bukkit/plugins)
  2. Run Bukkit server
  3. Start Minecraft and connect

I'm not sure that anything can be done about (3), but it seems to me that IDEA should be able to handle (1) & (2) in a single step. Also, we cannot presently debug using this configuration.

In Visual Studio / .NET, I would just need to specify the executable -- java/craftbukkit, in this case -- as an "external program", and it would solve all of these problems. In IDEA, though, it seems that I am supposed to add a Run Configuration, and I don't see an option which allows anything like a "host application." Instead, it wants the full classpath to the main for Bukkit, and it isn't clear to me what that would be. I have also seen it suggested elsewhere that even this won't work without a debug build of Bukkit. but I don't really want to debug Bukkit; I just want to debug our plugin code only.

I found these instructions for remote debugging Bukkit plugins, but is that actually necessary? It doesn't solve the "two steps to run" problem; it actually makes it worse!

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
  • 1
    I'll be interested in seeing the results of the question on this. I use Netbeans, but I have similar issues. I use the "remote debugging" option that you mention above, but I start the minecraft server manually (which eventually became advantageous, because I have multiple versions I test against). It could be that you could modify the build script to autolaunch the server after completing the build... – Iain Aug 24 '13 at 00:24
  • May I ask you why you have to use intellij idea? Have you searched for a tutorial and the writer said to use it? Or you absolutely want to use it? – Gerret Aug 28 '13 at 08:32
  • @Gerret, we don't *absolutely* have to use IDEA. But I haven't found a way which works in, say, Eclipse or NetBeans either. As far as I can see, Eclipse folks use the remote debugging method, which doesn't solve my problem. – Craig Stuntz Aug 28 '13 at 11:11
  • @CraigStuntz Ok I see, I found one thing, [that actully could solve your problem](https://forums.bukkit.org/threads/debugging-plugins-in-eclipse.4043/) but I am not sure about that. But it is made for eclipse. I program myself or better to say played around with bukkit plugins, but havent used the debugger for that, I just used a player.sendMessage(). – Gerret Aug 28 '13 at 11:19
  • @Gerret That might actually work; converting the instructions to IDEA should be easy. It does answer the question about the classpath. I'll fool around with it tonight and see how far I can get. – Craig Stuntz Aug 28 '13 at 11:27
  • @CraigStuntz I am going to convert my comment as an answer. If you need more help, just ask. I am tring my best! – Gerret Aug 28 '13 at 11:29
  • @CraigStuntz You have tried it? Would be intressting to know, if it works... – Gerret Aug 30 '13 at 13:21
  • Not yet. I'm going to try both proposed solutions this weekend. Building Minecraft plugins is not my paying job. :) – Craig Stuntz Aug 30 '13 at 16:46

4 Answers4

16

I realize this question is more than a year old, but I too had this problem recently and found no satisfactory answers. This is how I solved it, with help from @hunterboerner's answer.


First thing is you need to create an artifact that compiles the plugin JAR to the testing server's plugins directory:

  1. Go to "File > Project Structure > Artifacts"
  2. Add a new Artifact from the template "Other"
  3. Set "Output Directory" to the plugins directory of the testing server
  4. Under "Available Elements", right click the entry "'ProjectName' compile output" and then click "Pack into /ProjectName.jar"

If your project has no MANIFEST.MF file:

  1. Select the new jar file entry under "output root" and click "Create Manifest..."
  2. Navigate to the directory the project's java source files are kept (e.g. src/main/java/)

An example artifact configuration: example artifact config

Next, you need to create a Run Configuration that executes the Spigot server JAR:

  1. Go to "Run > Edit Configurations..."
  2. Add a new "JAR Application" configuration
  3. Set "Path to JAR" to the testing server's Spigot JAR
  4. Set "Working directory" to the directory of the testing server
  5. Under "Before launch", add a new "Build Artifacts" task
  6. Checkmark the artifact created above on the list

An example run configuration: example run config

After completing these steps, "Debug" the run configuration or press SHIFT+F9. This will automatically build the plugin JAR, copy it to the testing server and execute that server with full debugging facilities, including breakpoints and hot code swapping.

HeroCC
  • 988
  • 15
  • 33
Roy Curtis
  • 178
  • 1
  • 5
4

If you do not have to use IntelliJ IDEA, I would suggest you to use eclipse. I worked now over two years with eclipse, without any problems. The eclipse debugger has a really good overview on all values, so I think that that is not a problem.

To solve your problem, you could try to use that tutorial from GDorn. He describes, how to debugging a bukkit plugin with server. I have not tried that, but it seems that it is going to work.

Summary

First you have to open your run configurations and create a new application configuration. In your classpath tab, you have to remove all "User Entries". Ensure that the "Bootstrap Entries" contain the JRE library. Also add two external jars, the craftbukkit.jar (Bukkit Server) and the minecraft_server.jar (Vanilla Server).

I do not know why you have to add a Vanilla Server, I read that in the tutorial, you could try it without it. Otherwise, you are able to find it here.

After that, set your working directory in the argument tab. Save it and run it.

You can all read it accurate in the tutorial link. He describes it a little bit better than my summary. You also could try to use that informations, for your IntelliJ IDEA, maybe it gives you a tip how to solve it.

Community
  • 1
  • 1
Gerret
  • 2,948
  • 4
  • 18
  • 28
  • This does successfully run Bukkit, and the debugger also stops at breakpoints. I added the Bukkit folder as an external library in IDEA, which allows me to select org.bukkit.craftbukkit.Main in the run configuration. That meets my two criteria, so I'm awarding you the bounty. Having said this, however, it seems that Bukkit is unstable when running in the debugger (though not as unstable as Eclipse on its own). I'm going to fool around with the VM options to see if I have can improve this, but practical debugging is touch and go at the moment. – Craig Stuntz Sep 01 '13 at 20:56
3

First thing is you need to create an artifact. Example screenshot here:

artifact

That can be found under File>Project Structure

Then go to Run>Build Configurations and create a Maven config

You don't need to fill in any parameters. Go to before launch and add the artifact. Then click add, run external tool. Create one. Fill it in. Below is an example.

run external

Once that is added in the build config just go to Run>Run and it should run in the console below.

Community
  • 1
  • 1
hunterboerner
  • 1,264
  • 1
  • 11
  • 25
-1

I don't think that there is any possible way to automatically deploy and start the Bukkit server. IntelliJ requires the class with the main method to be defined in the run configuration, which you can't do unless you have the Bukkit source in your project. I'll do some further research, but I've looked into this topic before, and came out empty-handed. What I do as an alternative is make the plugin friendly with reloads, and just run /reload whenever you deploy a new version.

beechboy2000
  • 151
  • 6