Currently, I am trying to pass a system property to an executable in the following format: ./executable -Dvar="value" other parameters, since this is what I've seen people do for java files. I keep getting an error in the executable saying that -Dvar="value" doesn't exist as a parameter. Where am I going wrong? Are system properties exclusive to Java or something?
The -D parameter sets a system property. The system properties can be accessed through System.getProperty("<your parametername>");
A tutorial is given here https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
The -D is consumed by the java runtime (java.exe) and will be invisible to your application on the commandline.
Related
When invoking a jar file locally (and passing in a property) I use:
java -jar j.jar --A=B
however, another user on a different system uses:
java -jar j.jar -PA=B
Note the -P. I don't know much about the other system but this does not work for me and I can't seem to find any docs that explain how this -P flag works. Anyone seen a reference to this anywhere?
Note the property is read in the application using Springs Environment.getProperty("A") method
Java -XshowSettings dump the information such as VM setting. Where in the box/system this information configured or what is the source of the setting? Is there any property file ?
java -XshowSettings:all
The information comes from various sources; e.g. command line options, environment variables, values derived from the result of syscalls, default values hard-wired into the JVM executable, and so on.
Is there any property file ?
There are some system properties that are defined by property files in the $JAVA_HOME/cfg tree, but the majority of the properties and other settings come from other places.
I'm running in an environment where I can pass parameters but not set environment variables using a normal commandline.
I would like to set environment variables nevertheless. Is there an alternative way to "fool" java that an environment variable is set, e.g. using -D parameters?
(I'm running spark in oozie through hue; all in the Cloudera stack).
The java command itself doesn't seem to allow that. It has a -D parameter, but that sets Java 'system properties':
$ java -help 2>&1 | grep -A1 '\-D'
-D<name>=<value>
set a system property
Java system properties are a sort of Java properties. Like environment variables, java properties are key-value pairs, but aren't the same thing as environment variables: If your Java application reacts to a specific environment variable, setting a system property of the same name won't have any effect unless the application explicitly reacts to that property, too.
If your environment allows you to run arbitrary Java applications and if it allows your Java applications to execute other processes, you can write a little wrapper that sets the environment variables on a ProcessBuilder (see the question Arnon linked in his comment: How do I set environment variables from Java?) to then invoke java with your actual JAR from it. You could either hard-code the environment variables to set, or set them according to system properties the wrapper receives. (Or you could even implement your own shell in Java and pass a script to it.)
Though, if you can modify the source of that actual JAR, a much more idiomatic solution would be to make it itself react to properties instead of (or additionally to) environment variables. (Unless you have to control environment variables that the java command / the JVM reacts to rather than the JAR you'd like to run. Then this approach would not be applicable, of course.)
If you can run arbitrary Java code, you can create and run a Process using ProcessBuilder, including an environment of your choice.
Hence, write a java program that parses a command-line like
java -cp .... your.Prog FOO=BAR BAZ=BOOM command arguments ...
and starts command with the environment extended by FOO and BAZ
(Note that command could be java ...)
I am using Java and when I try to write an array into a CSV file, I encountered the following error:
The parser has encountered more than "64,000" entity expansions
I searched and found that I need to use entityExpansionLimit to solve this by typing in java command line: -DentityExpansionLimit=100000
But being new to Java and these kind of things, I don't understand where am I suppose to type that command. I tried typing that in command prompt but nothing happened
Can someone guide me? Am I supposed to navigate to a specific folder in command prompt?
With the option -D you can pass a system property to the jvm (see here).
For example if you run you application with
cmd> java -Dfoo=bar MyMainClass
then you can retrieve it in your application using the System#getProperty(String key) like this:
String foo = System.getProperty("foo");
System.out.println(foo); // will print bar
In you case the library that you are using is expecting to find a system property with the name entityExpansionLimit when "entity expansions" has exceeded the value 64,000 but it doesn't find it, i.e System.getProperty("entityExpansionLimit") returns null.
To pass that argument run you application by passing the jvm that system property
cmd> java -DentityExpansionLimit=100000 -cp <your-class-path> YourMainClass
I need to configure where the jvm crash logs are created. I like the name they have (hs_err_pid.log) but I want them created in an specific folder.
In here you can see that you can use the
-XX:ErrorFile=./hs_err_pid<pid>.log
param to set the FILE created, but if you set this to a folder, so the file is created in that folder with the original naming convention, it does not work, it is ignored.
I have been testing this by crashing jvm 1.6 from this questions, using this:
PathDasher dasher = new PathDasher(null) ;
Anybody knows a way to achieve this?
-XX:ErrorFile=/var/log/java/hs_err_pid%p.log works.
See http://www.oracle.com/technetwork/java/javase/felog-138657.html
The parameter does not allow for environment variables, but you can use environment variables in a launcher script (e.g. .sh or .bat) and the OS will do the substitution. However, this will use the value of the environment variable at the time of starting the JVM and not when the file is written later. Furthermore, environment variables do not work when setting Run properties in Eclipse.
The JVM will not create intermediate directories saving the crash dump. The crash dump will be saved at the default location if the specified folder does not exist.
You have to use this as
java -XX:ErrorFile=/var/log/java/hs_err_pid%p.log -Xbootclasspath/p:. Crash
in command prompt.
Here, Crash is my java file.