Friday, April 03, 2015

VertX Development with IntelliJ IDEA

Problem:


How can I develop Vert.X Verticles with IntelliJ IDEA?

Some Tips (May not be a Solution):


I have been trying to evaluate the Vert.X system (after getting my head spin around Activator + Scala), and believe or not, I have been in C/C++/C# woorld all this time and manged to avoid Java altogether (yes, you can have a whole career based on C# and JavaScript only!). So I am sure there are some figments of ignorance in this article. If you find anything wrong, please let me know as that will help me a lot.

As I stared on this path, I did find many other articles all over the net but I have found that most were written by seasoned Java developers directed to other still-a-bit-seasoned Java developers. This article is written by someone who hardly know much about Java. So if that's your situation this will help a lot, at least get to the point your Verticle to run and debug under IDEA.

Much of the hurdle in dealing with the Java environment (not so much with the language itself) is that  there is initial confusion as where all the classes come from (yes CLASSPATH) and there are more than one ways of doing things right. As a result it has gotten very time consuimg tasks to learn each of the paradigm. For example, there are Maven, Gradle and Ant to handle the builds just to name a few then there are things like Scala and Groovy and such to even confuse us, and on top of various Java frameworks for example Vert.X is one of them and Activator is another, then there are even more stuff like Spring, Netty etc.

Each serves slightly different purpose but they also get combined to do a lot of similar things like serving up Web APIs and web pages and such.

So with that in mind, here is probably very overly simplistic description of how to work IntelliJ with VertX development.

How To Start


I started with both Gradle based project initialization to Marven based. I have found that the Maven based one is a bit less intimidating to approach and lot simpler overall, so I also advise you try the Maven way first then do other stuff.

The most of how to set up the Maven based project skeleton is described on Vert.X document on THIS PAGE. But that page does not give you much more info on how to debug etc.

So first off, follow the directions on that page until you are all done and typed in "mvt idea:idea" to create the IDEA project. Then you can open the top level of your project (where you will find the IDEA files like .iml, .ipr and .iws). This will first convert the project format. Let IDEA handle that.

Integrating the Maven Project is the Key


After you open the project, and after a few minutes IDEA will say, it has found a Maven project and if you want to import it. Say yes. This will cause a small Marven Tab on the right hand side of the IDE.



What I have found out is that clean, compile and package commands (goals) are very handy.

For example, let's say you have added a new Verticle class. I have found that first doing the clean then do compile will make it appear in the target directory.

Now if you want to create the mod directory containing your Verticles, then doing package.


  • For each of the action, which is called Goal in Marven, select an item then press the Green start button above to execute.
  • clean will clean out any derived objects
  • compile should be used each time you update the source
  • package will create the mod directory in the target
  • install will also create the mod directory on the top level of the project, but what will be install is not always updated when you change the source.

Starting Verticles from Within the IDEA

For the reasons that I do not completely know, if you run "vert runnomd com...." stuff from the top directory of your project, it can find your module. So do not be afraid to use that option. But if you want to debug your updated verticle code each time via the mod then you can first do the "package" Marven goal first, then you can "cd" into your "target" directory then you can run the latest version.

Also not shown in this but instead of specifying Make before you debug, you can specify the Maven "package" goal which will always recreates the mod directory with the latest code. You may want to do that. Make takes forever to build, so I would at least switch to "compile" verb of the Marven and remove the Make action.





Adding or Running Your Own Verticle From Within IDEA

This is still an area that is a bit of mystry to me, but here is what I know so far and it does work, but the Vert.X documentation does not tell you how, so I had to do some experimentation to find what worked for me.

  • Go a head and add a new Verticle class under src/main/java/com.blah/ directory.
  • Do not remove PingVerticle.java If you do remove it what will happen is that it will break the build because there are some "tests" that will call this. You could, in theory, remove the tests too but why bother when you actually do not have to remove it.
  • If you want to run your own Verticle, you will have to go inside the "resources" directory, find mod.json and edit it to contain your class under "main": 
  • Now do a clean and then package and you will have your new Verticle to launch when you do runmod com.blah... stuff.
I am sure there are some errors in my post, but I feel that I have given you enough information that allowed me to do what I wanted to do. As I find more information, I will plan to update this document.




Post a Comment