I want a String in Java code whose value is set in a python script. Can I set it as a System Property from the script in order to use it with System.getProperty() method. Is there some way to achieve this or using some other approach?
23 Answers
If you are using pyspark you can use the setSystemProperty() method of the SparkContext, e.g.
import pyspark
sc=pyspark.SparkContext()
sc.setSystemProperty("com.amazonaws.services.s3.enableV4", "true") You can set a Java property on the command line like this:
java -D<propertyName1>=<propertyVal1> -D<propertyName2>=<propertyVal2> ...The System.getProperty("propertyName1") will return "propertyVal1".
Example:
java -Dfile.encoding=utf-8 -jar MyJar.jarThis will work in a bash script. I've never tried it from Python, but i guess this answer might help you achieve that.
If you are using Jython, you can import java.lang.System class and call the System.setProperty() method to set whatever system properties you want to set:
Code snippets:
from java.lang import System
System.setProperty('app.env', 'DEV')
from yourpackage import YourMainClass
args = ['Your','Args']
YourMainClass.main(args)