How to pass a system property using Wrapper.exe
Asked Answered
A

4

7

How do I pass a property to a Java process, started as a Windows service using Wrapper.exe?

The target code calls:

System.getProperty("ADMIN_USERNAME");
Ayr answered 9/3, 2009 at 4:27 Comment(0)
W
7

http://wrapper.tanukisoftware.org/doc/english/prop-java-additional-n.html

You can set "additional parameters" that will go to the JVM (as opposed to your main class), and -DADMIN_USERNAME=gandalf should work there.

wrapper.java.additional.1=-Xrs
wrapper.java.additional.2=-Dprop=TRUE
wrapper.java.additional.3=-DADMIN_USERNAME=gandalf

Update: You must start with additional.1 and count up without gaps (This is a convention for shoe-horning lists into Java properties syntax).

Winstead answered 9/3, 2009 at 4:39 Comment(7)
Sounds good but doesn't work for me unfortunately. I tried: wrapper.java.additional.3=-DADMIN_USERNAME=gandalf wrapper.java.additional.3=-DADMIN_USERNAME="gandalf" wrapper.java.additional.3=-DADMIN_USERNAME gandalfAyr
did you also have additional.1 (you must start with .1 and have no gaps)?Winstead
wrapper.app.parameter.1=-class demo.launcher.Launcher resolves to the correct class. And .2 is a parameter, not a property but it seems fine. Also tried rearranging the order to put -D options first, but not success.Ayr
I have accepted your answer because I think it is correct and helpful.Ayr
Please let us know if you figure out why it still did not work.Winstead
My error - it has to be wrapper.java.additional.x not wrapper.app.parameter.x - Thanks!Ayr
What If I have 20 properties? I need to set all of them like this? Is it possible to set the wrapper to read from config? For example I have config.properties file where I have kafka url and kafka password. So I want to set tanuki to start the service with the parameters that are in the properties. If I change them, after restarting the service, to start with that properties?Basilius
H
0

You can set certain properties in the wrapper config file, see this link:

http://wrapper.tanukisoftware.org/doc/english/properties.html

I believe you can also configure the wrapper to startup java and pass additional properties using the java "-Dproperty=value" syntax

Hemelytron answered 9/3, 2009 at 4:35 Comment(1)
What If I have 20 properties? I need to set all of them like this? Is it possible to set the wrapper to read from config? For example I have config.properties file where I have kafka url and kafka password. So I want to set tanuki to start the service with the parameters that are in the properties. If I change them, after restarting the service, to start with that properties?Basilius
A
0

This is a shot in the dark, but have you considered using JMX to communicate with the service? Or is this overkill for what you need?

Yuval =8-)

Affectional answered 9/3, 2009 at 5:7 Comment(0)
T
0

@Thilo's answer is correct but I feel I must add that you have to take care for JAVA_OPTS environment variable. Many people/servers tend to use it (e.g: remote debugging) as whatever you put into JAVA_OPTS is passed as JVM arguments to any new JVM. If you have this environment variable set then any wrapper.java.additional.<n> will be ignored. I found that on the hard way :)

Tourniquet answered 4/6, 2019 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.