How can I develop Vert.X Verticles with IntelliJ IDEA?
Some Tips (May not be a Solution):
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
Adding or Running Your Own Verticle From Within IDEA
- 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.