IntelliJ IDEA does not see my environment variables - java

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.

Related

Cannot find packages related to JUnit when compiling test code

Trying to get JUnit working on my computer. I'm using windows but I have also installed git bash as well (don't know if that makes a difference).
Anyway I've followed this tutorial linked below:
https://www.tutorialspoint.com/junit/junit_environment_setup.htm
I'm trying to set the environment variables manually on windows but the instructions above aren't working for me.
https://imgur.com/a/NaqFiue
^Here is a photo of my user variables after making the changes in the tutorial. On the above tutorial it says to link the JDK to a variable called JAVA_HOME, and mine worked perfectly with Path as seen in the image but it did not work with JAVA_HOME.
I'm honestly so confused, lost and frustrated. Any help would be appreciated.
Why does your classpath settings has so many semi-colons?
You haven't set JAVA_HOME yet. Usually it's necessary to set
JAVA_HOME, as it's assumed by most Java libraries. You can set the
Java path by %JAVA_HOME%\bin.
What is your commmand line to run Junit? Have you compiled
successfully?
JUnit has its own Getting Started. Can you try it instead of the tutorial that you used. It does not rely on environment variables. Therefore it should be easier to run it.

How to set a JVM option in Jenkins globally for every job?

I've recently installed a new JDK (1.7u9), and I got some very strange VerifyErrors. In a thread I found that it could help me if I use a -XX:-UseSplitVerifier magic switch for the compilation.
What I would like to do is to set this Java option globally in Jenkins, but haven't found any configurations for it. Can someone help me out how can I do this?
The closest thing I was able to come up with is to set the argument through Maven, but I have to do it for each project configuration - and I'd like to avoid that.
Thanks in advance.
Under the main menu item Manage Jenkins->Configure System you can set it in the box for Global MAVEN_OPTS.
It is a bit unclear whether you want the option turned on for the Jenkins container itself or only the jobs running in it, but if the latter and you're only running maven jobs, that's what I would do.
Cheers,
If you deploy the Jenkins to the Tomcat or Glassfish, I would like to suggest you to set further configuration as the following:-
The Tomcat
Set the environment variable named CATALINA_OPTS, e.g.
SET CATALINA_OPTS="-XX:-UseSplitVerifier"
EXPORT CATALINA_OPTS
The Glassfish
Edit the [your_domain]/config/domain.xml
<java-config ....>
....
<jvm-options>-XX:-UseSplitVerifier</jvm-options>
</java-config>
Anyhow if you deploy it to another application server, please refer to your application server administrator guide to configure further JVM options.
UPDATED:
If you only would like to apply this JVM option to the Maven project, please set the environment variable named MAVEN_OPTS, e.g.
SET MAVEN_OPTS="-XX:-UseSplitVerifier"
export MAVEN_OPTS
I hope this may help.
Regards,
Charlee Ch.
On Windows there's a jenkins.xml in Jenkins home directory. Simply add the required JVM options under arguments tag:
<arguments>
-Xrs -Xmx256m -XX:-UseSplitVerifier
-Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle
-jar "%BASE%\jenkins.war" --httpPort=8080
</arguments>
For most of the Linux distributions, modify JENKINS_ARGS inside file:
/etc/default/jenkins (or jenkins-oc)
For CentOS, modify JENKINS_JAVA_OPTIONS inside file:
/etc/sysconfig/jenkins (or jenkins-oc)
Apparently, the only way to set system-wide JVM properties in Jenkins is with a Groovy Script .
Create a init.groovy.d in Jenkins home and place a groovy file in it (load-properties.groovy). In the Groovy script, set system properties programmatically (see link above for details):
props.each { key, value ->
System.setProperty(key, value)
The above solution saved my day as I needed to disable jsse.enableSNIExtension during SCM checkout and it should be available to the SVN plugin, not to Maven.
There's a config.xml file with jdks/jdk/properties XML tags, but it's undocumented.

How to set Environment Variable in Netbeans?

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).

How can I retrieve environment variables(Jenkins) in java

I'm setting some environment variables by some windows batch commands in the pre-build steps for a Jenkins build. I need to use these variables for a few java selenium test cases which will run during as part of the build.
set HD_KF_TC_IN_LOOK_UP_KET_FEATURE_XLS = %WORKSPACE%\selenium_input_files\Key_Features\en_US
I have tried to retrieve these environment variable values by using System.getEnv(HD_KF_TC_IN_LOOK_UP_KET_FEATURE_XLS) commands. But this is not working as the values for these variables is always NULL.
Please let me know where I'm I going wrong?
As indicated in my comment, I do not completely understand your setup. In general, however, environment variables set in one Jenkins build step do not propagate outside of it and can't be accessed from other build steps. You need to use EnvInject plugin to achieve that.

Environment variables in Eclipse

I am able to run a sample hadoop program from the command prompt and am trying to run the same program from Eclipse, so that I can debug it and understand it better.
For the command line program, some environment variables are set in the .bashrc and the same are being read as System.getenv().get("HADOOP_MAPRED_HOME") in the hadoop program. But, when I am running a java program with System.getenv().get("HADOOP_MAPRED_HOME"), from Eclipse I am getting null.
I tried passing -DHADOOP_MAPRED_HOME=test to VM parameters in the runtime configurations from Eclipse, but still getting null in the standalone program. How to make the environment variables visible within Eclipse? When I iterate through System.getenv() in Eclipse, I see lot of variables like DISPLAY, USER, HOME and others. Where are they set? I am using Ubuntu 11.04.
You can also define an environment variable that is visible only within Eclipse.
Go to Run -> Run Configurations... and Select tab "Environment".
There you can add several environment variables that will be specific to your application.
I've created an eclipse plugin for this, because I had the same problem.
Feel free to download it and contribute to it.
It's still in early development, but it does its job already for me.
https://github.com/JorisAerts/Eclipse-Environment-Variables
The .bashrc file is used for setting variables used by interactive login shells. If you want those environment variables available in Eclipse you need to put them in /etc/environment.
You can set the Hadoop home directory by sending a -Dhadoop.home.dir to the VM. To send this parameters to all your application that you execute inside eclipse, you can set them in Window->Preferences->Java->Installed JREs-> (select your JRE installation) -> Edit.. -> (set the value in the "Default VM arguments:" textbox). You can replace ${HADOOP_HOME} with the path to your Hadoop installation.
You can also start eclipse within a shell.
You export the enronment, before calling eclipse.
Example :
#!/bin/bash
export MY_VAR="ADCA"
export PATH="/home/lala/bin;$PATH"
$ECLIPSE_HOME/eclipse -data $YOUR_WORK_SPACE_PATH
Then you can have multiple instances on eclipse with their own custome environment including workspace.
I was trying to achieve this but in the context of a MAVEN build. As part of my pom.xml configuration, I had a reference to an environment variable as part of a path to a local JAR:
<dependency>
<groupId>the group id</groupId>
<artifactId>the artifact id</artifactId>
<version>the version</version>
<scope>system</scope>
<systemPath>${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar</systemPath>
</dependency>
To compile my project, I had to define the environment variable as part of the run configuration for the maven build as explained by Max's answer. I was able to launch the maven compilation and the project would compile just fine.
However, as this environment variable involves some dependencies, the default "problems" view of Eclipse (where compilation errors/warnings usually show) would still show errors along the lines of Could not find artifact and systemPath should be an absolute path but is ${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar.
How I fixed it
Go into Window -> Preferences -> General -> Worksapce -> Linked Resources and define a new path variable.
Finally, in my case I just needed to Right click on my pom.xml file, select Maven -> Update Project and the errors disappeared from the "Problems" view.
For the people who want to override the Environment Variable of OS in Eclipse project, refer to #MAX answer too.
It's useful when you have release project end eclipse project at the same machine.
The release project can use the OS Environment Variable for test usage and eclipse project can override it for development usage.
I was able to set the env. variables by sourcing (source command inside the shell (ksh) scirpt) the file that was settign them.
Then I called the .ksh script from the external Tools

Categories

Resources