59

I have a project which runs correctly under the terminal command

mvn package exec:java -Dplatform.dependencies -Dexec.mainClass=Demo

Now, I need to debug it correctly (not terminal) with IntelliJ or Eclipse on Mac (preferably IntelliJ) but I have tried setting VM options in various places and nothing seems to work.

Where is the correct place to put these options: -Dplatform.dependencies -Dexec.mainClass=Demo?

diegomontoyas
  • 1,785
  • 3
  • 17
  • 22

4 Answers4

84

In IntelliJ it works as follows: Go to configurations -> VM options and add the parameter/value pair:

-DmyParameter=value

Make sure you add a "D" after the "-"!

enter image description here

ShadowGames
  • 1,110
  • 1
  • 10
  • 15
  • 1
    Are you sure that this works? On my system I have to add -D, otherwise, an exception is thrown. – MemLeak Oct 24 '18 at 11:59
  • 1
    This field is now hidden under 'modify options', allowing you to show the field mentioned here. – Thirler Jun 21 '23 at 07:24
50

In InteliJ goto "Run"->"Edit Configurations" In the new window, right panel, open the Junit and click on your test. Now, in the middle click on the "Configuration" tab and update the "VM options"

Note that you will need to do this for every test class, but you can remove all the test from the junit in the right panel and update it in the "Defaults"

Mzf
  • 5,210
  • 2
  • 24
  • 37
  • 2
    Thank you Mzf, but I created the test and I am still getting the error that I got before `java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil`, which I am not getting with the terminal command. – diegomontoyas Apr 05 '15 at 17:42
  • 1
    If you have to run numerous tests individually, it would be a hassle to have to define the property for each test. What you can do is to go to `Run` -> `Edit Configurations` -> `Defaults` -> `JUnit`; now add that property there to the `VM options`. Now every junit test you run will have that property defined. Make sure to remove the default when you move on from that project. – smac89 Oct 31 '17 at 22:23
  • 1
    Note that in some recent versions of IDEA, it seems that the `Defaults` section in the left pane of `Edit Configurations` has now been renamed to `Templates`. – amoe Nov 26 '19 at 12:00
  • `Run -> Edit Configurations` and then what? – daparic Oct 26 '20 at 05:04
4

Run -> Edit Configurations -> Modify Options (a blue link in the top right corner) -> [v] Add Vm Options -> fill in the extra input line 'VM options'

Ilya Kharlamov
  • 3,698
  • 1
  • 31
  • 33
2

If you are like me, and showed up here trying to run tests that use the -P syntax instead of -D syntax, you can simply follow the instructions from MZF, but use the -D in place of the -P.

For example, my test on the command line executed as:

./gradlew -Penvironment=qa project:test

Using the -P in intellij on the VM line got rejected. Changing the -P to a -D ended up working, however.

sanimalp
  • 799
  • 5
  • 12