I have lot of junits that depend upon the same jvm system props. Currently, I need to add these specifically for each of the junit's. The best I could do was to create a new VARIABLE and then reuse the variable across all these tests. Still, I need to specify this VARIABLE explicitly for each of the tests. Is there any way I can specify this at the eclipse level?
Under Preferences -> Java -> Installed JREs. You can edit the JRE installation and set default VM arguments.
Related
I've configured an environment variable in ~/.bashrc as well as ~/.profile.
When I run my application via IDEA's Gradle Configuration, my environment variable is apparently not available. E.g. I am referencing this variable within application.yml, but the default value is being used instead. Running Gradle from the command line correctly picks up my variable.
How can I configure IDEA to load this environment variable in a global way, so I don't have to manually add it to every project where I need it (~20 projects)?
Note: running on Manjaro Linux v18.
It turns out IDEA will pick up environment variables if you define them either in e.g. /etc/environment or /etc/profileor if you use ZSH,~/.zshrc`.
After setting variables, you to execute source ~/.bashrc and source profile to update and execute the file contents.
# josh-m I ran into the same problem in my IntelliJ IDEA setup with Maven.
In the end, I continued to keep the settings on each project, as there were not many, but when I studied the problem I found this IntelliJ support link:
https://youtrack.jetbrains.com/issue/IDEA-141832
At least at that time, this functionality was not available in IntelliJ directly, although the following plugin, mentioned in the comments of the support article, could perhaps be of some help:
https://plugins.jetbrains.com/plugin/7861-envfile/
launchctl setenv HADOOP_VERSION 3.1.1.7.2.8.0-SNAPSHOT
Execute in this way to set your environment variables in MacOS for them to be used by other applications.
After that restart your IDE.
I'm looking for some way to switch between default VM arguments. I've got a workspace with a bunch of projects and created run configurations for running JUnit tests. I'm able to switch between run configurations easily.
In order to run any test correctly, I need to pass some arguments to JVM. This is problem whenever I want to run a specific test method SHIFT+ALT+X,T. Since it creates a whole new Run Configuration, it doesn't pass any VM arguments to it.
I figured out how to set default VM arguments using Window -> Preferences -> Java -> Installed JREs -> Edit -> Default VM arguments. This, however, means that whenever I need to switch to different VM arguments, I'd have to do it manually.
What I'd need in the most optimal case is some select box visible on the toolbar, where I could switch between global run configurations from which all newly created ones would "inherit".
I'd also like to see a way to make automatically created run configurations destroy themselves as soon as I switch to a different one, because at this point, I have 36 run configurations (which I manually created) and I don't want to see a "garbage" from each test method I executed. Over the time, there might be thousands of Run Configurations in between which I'd have to search. I don't want to spent few minutes a day deleting them.
So, the recapitulation:
Is there a way to easily switch between default VM arguments?
Is it possible to keep the list of Run Configurations clear, meaning it will only contain run configurations I created?
What i already have:
Using eclipse keppler i am creating an eclipse plugin that is to work under linux, windows and mac.
I am trying to wrap some existing java code into this eclipse plugin. This works fine. The execution of the wrapped code can be started by clicking a button in the plugin ui. The wrapped code uses some environment variables. When these are set as environment variables and eclipse is then started the variables are found and used.
What i would like to do:
I would like to set the required environment variables in some textfields in the plugin ui and then start the execution of the wrapped code which should then use the variables form the textfields, so that i no longer need to set them as environment variables before starting eclipse. This would obviously be more flexible.
This feature is used by the eclipse ide itself when starting a run/debug-process. For these processes the environment variables can be set. This is the mechanism i would like to use.
My questions:
How is it possible to start a process from an eclipse plugin and provide it with a set environment variables that are set in the plugin ui?
Is it necessary to use ProcessBuilder or Runtime.exec() or is there some java-only solution?
Is the only way to find an answer to search through the eclipse souce code?
How is it possible to start a process from an eclipse plugin and provide it with a set environment variables that are set in the plugin ui?
Get the env variable names and values from your plugin UI.
Use ProcessBuilder or Runtime.exec() to launch a new (external) process with the appropriate environment variables.
(The 2nd step is the same as what you would do if you weren't using Eclipse.)
There may also be an Eclipse-specific way of doing this, but underneath the hood that will have to use ProcessBuilder or Runtime.exec().
Is it necessary to use ProcessBuilder or Runtime.exec() or is there some java-only solution?
If you want to run the Java code as a separate process, then at some level you have to use ProcessBuilder or Runtime.exec(). Conversely, while it is possible to run a Java application in "the current JVM", you won't be able to change the environment variable settings for the current application. (The Map you get from System.getEnv() is documented as "not modifiable".)
(I'm not sure what you mean by "java only". You could argue that one JVM launching another using ProcessBuilder or Runtime.exec() is "java only".)
Is the only way to find an answer to search through the eclipse souce code?
No. You could also find the answer by reading the javadocs ... like I just did :-)
I am running maven based Spring project in netbeans . I am using an environment variable in my project configurations file to Open specific file based on that variable value . I am able to set it In Eclipse but do not know how to set in Netbeans . Can any one help me?
System.getEnv("FOO") == "FOOVALUE"
netbeans 6.7+ -
Right click Project
->Properties
->Actions
->Run project
->Set Properties: Add
Env.FOO=FOOVALUE
Note: You can apply the same technique on other configurations and other actions like Debug project
I could not find that Properties->Actions setting, using NetBeans 7.4. I did not explicitly need an environment variable--just some value I could set outside my application. So, instead, I was able to make a change in the "project.properties" file under the nbproject folder of the main application.
Within project.properties is a "run.args.extra" setting. Any command line argument you wish to pass along must have its 'name' preceded by '-J'. Here is an example.
run.args.extra=-J-DFOO=FOOVALUE
Note that this is NOT an environment variable. Rather, it is a System.getProperty("FOO") accessible value. Of special note: this is also the place to change how much memory your applications allocate, using Xmx/Xms.
On macOS:
In $HOME/.bashrc add alias:
alias netbeans='/Applications/NetBeans/NetBeans\ X.Y.app/Contents/MacOS/netbeans &'
In Terminal:
> netbeans
This will start IDE with user environment variables.
As result environment variables (such as $PATH) available inside NetBeans IDE and tools (such as Ruby debugger).
I need to pass a VM parameter to every test that is run in the project. Setting this manually doesn't seem to be the most convenient solution, so is there any possibility to pass the parameter to every test automatically.
Thank you for help.
We change the JRE Configuration in Eclipse (Preferences>Java>Installed JREs). There you can set default VM Arguments which are used for anything you run with that JRE.
Now simply configure your project to use this JRE (Java Build Path) and you should be on the right way.
Eclipse have already a built-in JUnit for you.
You can use JUnit to run different parameters on your main program.
Run your test once, this creates a run configuration.
Run-> Run Configurations -> JUnit, select your run configuration, then you have an arguments tab to specify JVM or program arguments.
You can then duplicate this run configuration to use for other tests. I'm not aware of any way to make a default setting to be applied to all future test launches.
I think you are using "Program Argument" instead of "VM argument" now. If you use VM argument it's mean globally applied to all of your tests.