aspose file tools*
The moose likes Linux / UNIX and the fly likes Picked up _JAVA_OPTIONS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Picked up _JAVA_OPTIONS" Watch "Picked up _JAVA_OPTIONS" New topic
Author

Picked up _JAVA_OPTIONS

bisanthe qerf
Greenhorn

Joined: Jan 31, 2009
Posts: 6
Hello,
We are using Solaris as a build machine. But have to set java temp directory per user. So we have added this line to .cshrc file.
setenv _JAVA_OPTIONS -Djava.io.tmpdir=$HOME/tempdir

This changes temp dir as desired but, this will also shows
Picked up _JAVA_OPTIONS: Djava.io.tmpdir=..... message at console.
java writes this message to stderr. How can i disable it ?

Because our ant script catch this message, ant thinks there is something wrong. Our build fails.
We dont have a chance to change ant script. I tried everything, but i could not find a solution.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

"bisanthe bisanthe " welcome to Javaranch
please see your private messages for an important administrative matter.


SCJP, SCWCD.
|Asking Good Questions|
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Thanks for fixing your display name Bisanthe, and welcome to the JavaRanch.

We need some more information. Normally I'd expect the setenv to be done before Ant is run, so Ant shouldn't care. And they wouldn't be written by Java, they'd be written by the C shell. If Ant is invoking a shell script we need some details such as the part of the build.xml file that does the script invoking.

I normally use bash shell and the form:

_JAVA_OPTIONS=-Djava.io.tmpdir=$HOME/tempdir

which doesn't result in console messages. Although I should mention that normally you wouldn't start a shell script variable name with an underscore character. Plus, if you want to be totally conventional, the usual tempdir name in Unix/Linux is "tmp", not "temp". So what I'd actually be doing (and actually have done) would look like this:

JAVA_OPTIONS="-Djava.io.tmpdir=$HOME/tmp"

Note the double quotes. Single quotes wouldn't work right (no variable substitution), I think for this kind of declaration quotes may be omitted, but this is the safe way.


Customer surveys are for companies who didn't pay proper attention to begin with.
bisanthe qerf
Greenhorn

Joined: Jan 31, 2009
Posts: 6
Ok,
I think _JAVA_OPTIONS environment variable, is a special environment variable, which jvm looks for when it is initialized.
It does not have to be solaris. I tried in windows too. I have defined _JAVA_OPTIONS environment variable and then i typed java at windows console.
Ok everything is normal except Picked up message. Can not java be stay silent ? Does it have to say, what did it picked up.
Output is:
Picked up _JAVA_OPTIONS: -Djava.io.tmpdir="C:\temp"
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument

-splash:<imagepath>
show splash screen with specified image
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Java is "write-once, run anywhere". Because of that, it doesn't depend on environment variables because while most OS's do support an environment, not all do. There was, in fact, a long, bitter struggle waged on between developers and Sun because for a long time Java couldn't easily access environment variables at all. They finally realized that an OS with no environment was equivalent to an OS with no set environment and gave in. That made life easier for those of us who write apps that get configuration info from the environment.

Having worked with Java since about 1996, I've never seen Java depend on any such variable as _JAVA_HOME.

Some Java applications have conventions. For example, Tomcat and WebLogic among others look for a JAVA_HOME, but that's used by the startup scripts, not directly by the JVM. In fact, you can set up a JAVA_OPTIONS for Tomcat, but it will ignore a "_JAVA_OPTIONS".

You're not showing us the input so we don't know what you're doing. The output is what I'd expect to see if I typed in the "java" command with an invalid option. For example: "java _JAVA_OPTIONS=$HOME/tmp" would result in a message like that.
bisanthe qerf
Greenhorn

Joined: Jan 31, 2009
Posts: 6
Ok,
Then i want to ask this;
Is _JAVA_OPTIONS environment variable special for java ?
If you define _JAVA_OPTIONS and call java from console it prints a message Picked up _JAVA_OPTIONS ... message
Why ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

bisanthe qerf wrote:Ok,
Then i want to ask this;
Is _JAVA_OPTIONS environment variable special for java ?

As I said, no environment variable is special for java. The JVM is not allowed to use environment variables because it would make Java non-portable. Microsoft tried to make a non-portable Java and Sun sued them (and won). Which is why there's no such thing anymore as Microsoft Java. Portability is a critical component of Java.

If you define _JAVA_OPTIONS and call java from console it prints a message Picked up _JAVA_OPTIONS ... message
Why ?


It doesn't do that for me. I've never defined a "_JAVA_OPTIONS" in my entire career or even heard of anyone else doing so. But when I do define a "_JAVA_OPTIONS", it doesn't do what you say.

It never has done so for me or anyone else I know in all these years of working with Java.

I don't know what you're doing that gives you that message. My best guess is that you're executing a script and the script is printing the message, then it tries to start up java using an invalid java command line, so java rejects it, prints the java command-line options and then exits. But that's only a guess, because I don't know what you are actually typing in.
bisanthe qerf
Greenhorn

Joined: Jan 31, 2009
Posts: 6
Why is this not working _?
As i understand, java looks for TMPDIR environment variable when we call System.getProperty("java.io.tmpdir");
In .cshrc file I have set
setenv TMPDIR "/users/u6/myusername/tempdir"

but System.getProperty("java.io.tmpdir"); still gives /var/tmp/
I dont understand how System.getProperty("java.io.tmpdir"); decide which directory is temp directory ? How can i edit it.
by the way i cannot use -Djava.io.tmpdir
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Java doesn't use environment variables. At all. Ever. Still. Honest!

Here's what the JavaDocs say about the temporary directory:

The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\\temp". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the the temporary directory used by this method.


Which basically says that you can't reliably select an alternative temporary directory in program code. Mostly because of multi-threading concerns, I think.

In other words, if you can't put a "-Djava.io.tmpdir=$TMPDIR" (or for Windows -Djava.io.tmpdir=%TMPDIR%) on the java command line, you may be stuck with the default temporary directory location.
bisanthe qerf
Greenhorn

Joined: Jan 31, 2009
Posts: 6
Why is this working on window ?
In windows TEMP and TMP environment variables are set to D:\Profiles\myusername\Local Settings\Temp
When I call "java Test"
Output is : temdir->>D:\Profiles\myusername\Local Settings\Temp

I am changing TEMP and TMP to C:\tesdir
Then again I am calling "java Test"
Output is : temdir->>c:\testdir\


Java doesn't use environment variables.


I am not sure

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Well, let me put it this way. Sun doesn't document such a usage, Google searches don't give me anything. Technically, one CAN write a JVM to default java.io.tmpdir to an environment variable value, but there are a couple of reasons why it's probably not a good idea.

1. As you've illustrated, DOS/Windows was never consistent in which of two different variables was supposed to be the definition for writing temp files. What happens when you set TEMP and TMP to different values?

2. Windows rearranges things frequently, so it's important to consider which version (and maybe edition) of Windows you're talking about. Originally - as the Javadocs indicate - the most common location for tempfiles was in C:\temp or sometimes C:\tmp. However, somewhere around Windows XP they tried to re-invent the Unix idea of a /home directory but with a cute Microsoft name (containing embedded spaces so as to confuse command-line parsers). One thing you should note is that implicit in your illustration is that each user would have a distinct temp directory. When you're talking things like servers that are shared across users, you can end up with NTFS file access rights problems. Plus, I'm nut sure who normally has write rights to the "All Users" user directory on versions of Windows that have such a thing.

2. As far as I know, there's no TEMP/TMP environment variable convention at all on Unix/Linux. Individual apps can do whatever they want, but there's no master setting. In Unix and Linux, environments are propagated and shared or created from scratch depending on the options used to spawn the process or subprocess. On my machines, neither TMP nor TEMP were ever set at all. And, of course, since there's no enforcement on such things, if someone wanted to set TEMP to a string that was unrelated to a file system location, there's nothing to prevent it, but a Java app that didn't know about it would encounter difficulties, breaking the "write once/run anywhere" rule.

I never argue with success. Or at least I try not to as long as it's not illegal, immoral or lacks redeeming features. So if you can get what you want by setting an environment variable, be my guest. All I can say is that it's not a mechanism that you can count on to run reliably at all times and in all places.

Sun has their own official Java forums. I don't hang out there because they are high traffic and unlike the JavaRanch, they don't have a no-flaming policy. But if you want a definitive answer, ask there. I'm quoting the docs, but the docs are based on what they actually decide. Let us know what they say!
bisanthe qerf
Greenhorn

Joined: Jan 31, 2009
Posts: 6
Thank you tim,
I will dig it more in sun forums.
your answers made it more clear for me.
thnks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Picked up _JAVA_OPTIONS