Is there an option to define default JVM arguments in IntelliJ IDEA?
For example, I would like to always activate:
-ea -Dslf4j.detectLoggerNameMismatch=true
In Eclipse, the option can be found in:
Preferences -> Java -> Installed JREs -> Edit -> Default VM arguments
You have to do it per run type (Application, JUnit test, etc).
In the "edit configurations" window ("Run" ▸
"Edit Configurations..."), expand the "Defaults" item, select the appropriate run type, and edit its defaults in the left pane.
The full documentation is available in the IDEA docs.
You can set your VM options for all applications as a default by picking the application type (for command line Java programs it would be 'Application') under the 'Templates' tree found via the menu items Run/Edit Configurations... Then all new applications you create will use that default. Older versions of IntelliJ IDEA labeled that tree 'Defaults'.
This is the field in the Run/Debug Configurations dialog you need to edit:
Related
While developing some plugins based on Eclipse, I need to add some default VM arguments when user right click-> "run as" -> "java application" or "spring boot app", is there any open api I can call or any extension point?
Just like the snapshot below, the argument "-Daaa=bbb" is added by default.
Any help is appreciated.
You need to write your own plugin and need to replicate/extend Java launch configuration
(of type Java application) from JDT and add -vm argument programmatically.
But there is one more easy way: Try LcDsl.
LcDsl provides a way of defining Eclipse launch configurations in a textual way. The file extension used is '.lc' It provides some obvious and some non-obvious advantages over the Eclipse launch configuration solution.
For more info look here and check demo videos. Also there was a discussion going on to include this plugin in JDT itself, see this bug entry.
A typical Java launch configuration looks like this:
java configuration LcJavaMain {
project com.wamas.test;
main-class com.wamas.test.JavaMain;
memory min=64m max=256m;
vm-argument '-Dmy.arg=value';
argument 'cmdArg';
}
I debug a simple java application on Eclipse in debug as and step into java resource bundle which got interrupted exception in line construction.getCause
How do I trace each variable and express to see the values from java library?
In j2ee, I can point mice at params, vars and assigned value from express, how do I see it in java application?
Why it cannot find the resource MyBundle base for MyBundle_zh.properties under project src?
Screen shot: https://plus.google.com/collection/UFuOlB
https://lh3.googleusercontent.com/ibrMgi8udPlaAIvyvPKc4tE5Agw5SzXxi5yp0a3yZJA5zNkYymSPgFHUEsO_tD2HsDMUZzE2=w640-h360-p-rw
Thanks
Eclipse has different Perspectives, you can switch them from Window -> Show Perspective. Each Perspective can have a different set of views. In you case, make sure that you have the Debug Perspective open and then (if you don't have it there already) do:
Window -> Show View -> Variables
Then, when your execution stops on a set breakpoint, you will be able to inspect all the relevant variables in the "Variables" view.
Your Installed JREs preference page, project Java Build Paths, and launch configurations should not be using "c:\Program Files\Java\jdk1.7.0_04\jre". They should instead just point to "c:\Program Files\Java\jdk1.7.0_04", after which the Java platform sources will be shown and debugging features you expect will work more automatically.
Is it possible to have some sort of debug/release configurations that I can chose between so i can have some variables altered when compiling my project?
For example, alternate between database login variables or turn off some output debug variables.
Thanks
For Java projects in NetBeans, you can create multiple configurations. Right click the project in the Projects window, choose Set Configuration > Customize. In the top right of the new window, for Configuration, choose New.... Give the new configuration a name and click OK. Now you can set different command line switches (Arguments) and VM Options for the new configuration.
Any configuration that you create here you can then choose from the project's context menu (right click, select Set Configuration > MyConfig).
This kind of configuration is easily handled via command-line -D parameters, which should be settable in the run configurations, or via configuration files which can be selected the same way (usually cleaner, if there's a bunch of parameters).
Depending on frameworks in use there are also multiple ways to handle this.
I'm writing a Java library with a lot of jni code. Pretty much every test case needs to load my jni dll, and I have a lot of test cases. In order to run the test cases out of Eclipse's Junit launcher, I have to create a run/debug configuration and edit the VM arguments and environment variables.
I would like a way to set the VM arguments and environment variables to a default for the entire project and have new run configurations include the default entries. From what I can tell, Execution Environments maybe do something like this but I seem to need the PDE to get them to work(?)
Specifically, I want to enable assertions on my project by default and include the path to my native dll in the PATH environment variable. I can't use the "Default VM Arguments" setting in the JRE definition panel because my dll depends on a number of others and java.library.path isn't used for dependency resolution, PATH is. Is there a way to make Eclipse do what I want?
So, here's what I did.
First, my specific problem was that I have a lot of run configurations, I create new ones on the fly, and I needed certain system properties set for unit tests. Setting them under the 'args' tab of run configurations was undesirable for my workflow. Also, I wanted the same command-line args set for all of my tests. I also don't run my app from inside eclipse. It's a dev-environment only.
So my solution was to add it to the command-line of my JRE. Preferences -> Java -> Installed JREs. Clicking edit gives you a window where you can specify default VM args. I just set the system properties I need for testing there.
Hope this helps.
How long does it take to run all of your tests for the project?
If the answer is Not long then create a project-wide JUnit launcher. If occasionally you would need to do a run on a single test case ( in order to debug or something ), you can copy all your settings from the project's junit launcher. I think you can even clone your project launcher to run a specific test case.
Run->Run Configurations...
Create new JUnit launcher.
On 'Test' tab select Run all tests
in selected {...}
Connfigure JVM options, classpath,
environment etc. for this launcher
Optional, but highly recommended. On
Common tab -> Save as -> Shared
file, and check-in launcher with
your project
One more thing I would do is to define a system property in launcher VM arguments, check for this property in #Before function and throw exception if the property is not set. This way you will know that your test fails because it is not using the right launcher.
If I understand your question correctly, I think Alexander is on to the idea with cloning the project launcher. Eclipse lets you duplicate launch configurations with a single click - simply setup one configuration with the parameters you require and click the button in the top left to duplicate it whenever you create a new one.
When I implement new features using TDD, I often use the shortcut Shift + Alt + D T to run only the jUnit test case I am currently working on (and not the whole test suite, which takes a few minutes).
This creates a new Debug Configuration for the current Java source and runs it immediately. Now I would like to run the test with assertions enabled (VM option -ea).
Unfortunately, the VM arguments for the new debug configuration starts empty. I always have to go into Debug Configurations... → Arguments and add -ea to the VM arguments input box.
Is there any way to have Eclipse these arguments populated with (project or workspace wide) default options?
I think you can set this option by editing the definition of the JRE under Preferences → Java → Installed JREs → Select the JRE in question and edit the default VM arguments
Windows → Preferences → JUnit has an option to add -ea every time a new launch configuration is created. It adds the -ea option to the Debug Configuration as well.
The full text next to a check box is:
Add -ea to VM arguments when creating a new JUnit launch configuration
Only way I can see to do it is to contribute a new launch configuration, this is not a trivial task but not too hard if you have PDE experience.
There is an eclipse.org article (see "Creating a Launch Configuration") that describes how to construct configurations and launch them.
I guess you could copy the JUnit implementation (see the org.eclipse.debug.core.launchConfigurationTypes extension in org.eclipse.jdt.junit) and add in your chosen defaults to that config. You'd then need to declare a key binding to launch it and package the plugin to your install.