How to set Environment Variable in Netbeans? - java

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

Related

IntelliJ IDEA does not see my environment variables

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.

The specified task executable location "C:\Program Files (x86)\Java\jdk1.7.0_71\\bin\javac.exe" is invalid

Ok im wondering where does xamarin get this path from?
Severity Code Description Project File Line Source Suppression State
Error The specified task executable location "C:\Program Files (x86)\Java\jdk1.7.0_71\\bin\javac.exe" is invalid.
So I can go and change it to the new jdk1.8. I have the new JDK set up I just need to know where to change the path at.
I had the same problem and solution is.
Remove all jdk and install jdk 1.8
Change reference java location in Visual Studio Tool > Options > Xamarin
Clean and Rebuild Project
I've just solved this exact problem for me.
I don't know why you wouldn't have a JDK_HOME variable. Completely remove the JDK and install it again maybe?
The Environment Variables for java were set to my previously installed path. I guess Oracle screwed up here.
As I had the same error, here's what I did:
I went to C:\Program Files\Java\ and checked what the jdk folder is called. For me it's jdk1.8.0_102.
For users who don't know where to find System Variables:
Go to System Properties and on the left hand side, click Advanced System Settings. Switch to the Advanced tab, click Environment Variables. Under System Variables there should be two variables in the list called JAVA_HOME and JDK_HOME.
I edited those values and change the path to what I found in the java folder. In my case this would be C:\Program Files\Java\jdk1.8.0_102.
No need to close VS, just build your app and it should get passed the annoying error.
Hope this helps :)
I had exactly the same problem. I got it to go away (which is not the same thing as fixing it).
Un-install every bit of JAVA you have. Delete both JAVA folders (Program Files and Program Files (x86)).
Install the latest version of the Java (x32) SDK.
Clean and Rebuild your project(s).
Since my Solution is multi-platform, I changed the Startup Project to the .iOS one, built it, ran it in an emulator, and set the Startup Project back to the .Droid project.
Somewhere in all this, the problem went away.
And remember kids! If it can go away all by itself, it can come back again all by itself!
I had this issue as well, I downloaded 32 bit Java but VS was still looking for the 64 bit one.
To solve it all I had to do was change the JAVA_HOME and the variable in my Path, clean my project and rebuild it.
Just set JAVA_HOME and JDK_HOME ambient variables, clean your solution and build again. For me worked fine.
Don't forget to clean your solution.

Eclipse with EclipseLink: How?

I am using ubuntu. I want to build a JPA project with eclipse. According to that tutorial I need to have EclipseLink.
Therefore I went to EclipseLink download page, got .zip achive and tried to follow instuctions - set the paths.
JAVA_HOME - Set JAVA_HOME to where you installed your Java SDK home >directory
UNIX example: JAVA_HOME = ...:/usr/java/jdk
PATH - Set PATH to include JDK/bin directory.
UNIX example: PATH = ...:/usr/java/jdk/bin
okay. My SDK Eclipse, and it is located in /usr/lib/eclipse. Though I also have /usr/lib/java/swt-gtk-3.8.jar. What should I use here?
Next. Then I take unziped eclipselink folder. It is written, that I should make path to it:
UNIX example: ECLIPSELINK_HOME = ...:/usr/el/INSTALL_DIR/eclipselink
So, for example, I place it like this:
ECLIPSELINK_HOME=/home/laura/lib/eclipselink
Please, help me. Are my steps correct? What I need to do after set all paths?
So, here you are. The answer qas quite simple: I should have had installed the newest version of Eclipse, where I would have an option to make a JPA project. Then goes an option to choose a platform, EclipseLink, for example.

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.

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