How to ignore JAVA_TOOLS_OPTIONS for a particular jar? - java

Installing FireEye sets JAVA_TOOL_OPTIONS and when launching my application jar, following message is shown and jar is not launched:
Picked up JAVA_TOOL_OPTIONS:
-agentpath:"C:\Windows\FireEye\JavaAgentDll_00.dll" Cannot open project
Following SO post suggested to unset the JAVA_TOOL_OPTIONS variable but I don't want to change global settings. Is there an option to bypass this variable check(i.e. ignore JAVA_TOOL_OPTIONS) while launching my jar?

Use batch file like this.
#setlocal
#set JAVA_TOOL_OPTIONS=
java -jar your.jar
#endlocal

Related

'JAVA_HOME is not set' error while installing pig. What to do about it?

I followed all the steps on pig.apache.org ,but not able to remove this error by setting java variable. I set the variable earlier while installing java jdk but its asking again for the variable.
You need to understand how environment variables work in Linux (or Windows).
The chances are that you only set JAVA_HOME temporarily in the shell that you used to do the installation. To set JAVA_HOME permanently (on Linux / UNIX) you need to set it in a shell "rc" file that gets run each time a new shell is created. (It depends on which shell you are using, but man can tell you about that ...)
if you are installing PIG on ubuntu do this
open bashrc file using below command and and lines to the end of the file
vi ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-i386
then log out or Restart your system and try again.
For CentOS
Create a new file called java.sh
vim /etc/profile.d/java.sh
Within this file, initialize the necessary environment variables
export JRE_HOME=/usr/java/jdk1.5.0_12/jre
export PATH=$PATH:$JRE_HOME/bin
export JAVA_HOME=/usr/java/jdk1.5.0_12
export JAVA_PATH=$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
Replace java path with your java installation.
Source
To set your JAVA_HOME variable for your current shell, use the export command. This will immediately create an environment variable for JAVA_HOME, but the variable is lost when your shell is closed.
export JAVA_HOME=<path_to_java_sdk>
The best way to set the JAVA_HOME environment variable for Pig and Hadoop use is by adding it to your local rc file. The reason for this is that some distributions of Hadoop (Cloudera, Hortonworks, MapR) may include their own Java installation for the Hadoop application itself. You may not want to create a global environment variable, since it may interfere with Hadoop/Hive/etc.
To have the variable set for individual Hadoop/Pig users on the server, they need to run the following command:
echo "export JAVA_HOME=<path_to_java_sdk>" >> ~/.bashrc
Afterward executing the command, they can source ~/.bashrc to instantiate the environment variable.

Loading Environment Variables in java through the Ant script

I'm using jibx to convert a xml to JAVA and vice versa. Here, in an Ant script, I'm using the following code to load the JIBX_HOME path from the environment variable:
<property environment="env"/>
<property name="jibx-home" value="${env.JIBX_HOME}"/>
I have set the JIBX_HOME environment variable to .bashrc as follows:
export JIBX_HOME=/rezsystem/jibx_1_2_2/jibx
But this path is not loaded to the jibx-home property.
When I simply type $ set command in the terminal it prints. JIBX_HOME=/rezsystem/jibx_1_2_2/jibx successfully. What have I missed here? My OS is Ubuntu 12.10 and my IDE is Eclipse kepler.
I think you also have to add your environment variable with PATH also
like:
export JIBX_HOME=/rezsystem/jibx_1_2_2/jibx
export PATH=$PATH:$JIBX_HOME
Make sure you add the line to the current bashrc
like, key in on a shell,
vi ~/.bashrc
or
gedit ~/.bashrc
then enter the line at the end,
export JIBX_HOME=/rezsystem/jibx_1_2_2/jibx
don't use sudo command, save the file and restart the system.
If you print out the environment property using echo then is it set properly?
Ant properties are immutable anyway so you can just remove the entire not condition as you can't override the jibx-home property using your condition.
Try running eclipse with:
bash -ic "path to eclipse"
Do this after exporting JIBX_HOME variable.
I had to change my link to eclipse to this because it was not loading all env variables.
Try setting these environment variables in your .bash_profile instead.

How to correct configure grails on a ubuntu terminal?

I have the following on my .bashrc:
JAVA_HOME="/usr/bin/java"
GRAILS_HOME="/root/grails"
PATH=$PATH:$JAVA_HOME:$GRAILS_HOME/bin
export JAVA_HOME
export GRAILS_HOME
export PATH
However, when I execute > grails in the terminal, I get:
root#localhost:~# grails
grails: JAVA_HOME is not a directory: /usr/bin/java
when I tried to replace to
JAVA_HOME="/usr/share/java"
then the outcome is:
root#localhost:~# grails
grails: JAVA_HOME is not defined correctly; can not execute: /usr/share/java/bin/java
what am I missing in there?
I would expect JAVA_HOME to contain the bin directory containing java (and others).
So clearly those two options you've selected are not correct.
Looking at my Ubuntu installation, I have numerous Java packages under /usr/lib/jvm, and I would select an appropriate one there e.g.
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
Make sure to source the changed file eg: $ source [filename of the changes made] in your example .bashrc

setting classpath using setenv.sh for a project

I want to write an sh file that will set classpath in Linux.
I tried using:
export ClASSPATH=$CLASSPATH:$ABC_HOME
However, when I run the .sh file it doesn't set the classpath.
Executing the bash script only sets the environment for the child process. The "source" command may do what you want...
https://askubuntu.com/questions/53177/bash-script-to-set-environment-variables-not-working
You should make it a shell function, or source it. Because the environment variables are local to the shell (the one started by invoking your shell script).
Please read the advanced bash scripting guide. See also this answer to a similar question.

CLASSPATH issue while accessing Mysql on Linux

I have Mysql installed on my Linux box and wrote a sample program to access one of it's table.
I am using 'mysql-connector-java-5.1.10.jar'
The code is working fine if i put the jar in 'jre/lib/ext'. However, other ways of recognizing that jar are not working. I tried with setting $CLASSPATH and tried to use '.' current directory.
It's failing with the following error :
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
I usually don't use the global $CLASSPATH variable, the easiest way to get it running is
java -cp .;/path/to/mysql-connector-java-5.1.10.jar[;<other libs>] pkg.name.MyApplication
Sidenote
If you have your application exportet to a jar with a Main-Class attribute ("executable jar") and start it with java -jar myjar.jar, then you have to add all required libraries to the jars manifest, $CLASSPATH and -cp are ignored in this case. And that's why I usually don't use the -jar option...
Edit
To answer your additional question: If the current directory was added to the classpath by default, then the location from where the application was started could influence the application itself.
Imagine an application inside a jar and a start command
java -cp application.jar com.example.Main
Now we have a defined environment: only the content of application.jar (and the jre classes) are on the classpath and part of the application. If the current directory was added to the classpath automatically then all files at the current location (and at locations of all subfolders) would be on the classpath too, intend or not. With a result, that the application might work if started from the users home directory but maybe not if started from the root directory (/).

Categories