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?
Asked
Active
Viewed 1.4k times
3
-
You may use Jython ans reverse the problem – Aubin Nov 10 '12 at 12:40
-
Depending on the concrete task of the java application it may also be more appropriate to pass the value as a simple command line argument. – raymi Nov 10 '12 at 12:56
3 Answers
4
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")

asmaier
- 11,132
- 11
- 76
- 103
2
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.jar
This will work in a bash script. I've never tried it from Python, but i guess this answer might help you achieve that.
0
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)

Fengzmg
- 710
- 8
- 9