如何配置Tanuki Wrapper实现Jar包自定义参数启动?
Got it, let's get your custom startup arguments working with Tanuki Wrapper. Here's exactly what you need to add and adjust in your configuration:
1. Understand the Parameter Structure
Since you're using org.tanukisoftware.wrapper.WrapperJarApp as the main class, this helper class forwards arguments directly to your application JAR. You’ll use the wrapper.app.parameter.* configuration keys to define these arguments.
2. Update Your Configuration File
Add these lines to your existing Tanuki config (adjust paths and parameters to match your setup):
# First, specify the path to your application JAR (tells WrapperJarApp which JAR to launch) wrapper.app.parameter.1=/opt/folder/lib/app.jar # Add your custom arguments one by one, in the exact order you want them passed wrapper.app.parameter.2=--zk wrapper.app.parameter.3=localhost:2020 wrapper.app.parameter.4=--uri wrapper.app.parameter.5=localhost:1919
Key Notes:
- The numbering for
wrapper.app.parametermust be consecutive (start at 1, increment by 1 each time—no gaps allowed). - If your app already has default arguments in the config, you can either replace them with these custom ones or append your arguments after the defaults (just adjust the numbering to keep it sequential).
3. Optional: Dynamic Argument Passing (Avoid Hardcoding)
If you want to pass arguments on-the-fly when starting the Wrapper (instead of writing them into the config), do this:
- Start the Wrapper with the
--flag followed by your custom arguments:./wrapper start -- --zk localhost:2020 --uri localhost:1919 - To make this work, add this line to your config to let the Wrapper forward command-line arguments to your app:
(This tells the Wrapper to treat any arguments afterwrapper.app.parameter.prefix=--as application parameters.)
Verify Your Setup
After updating the config, start the Wrapper and check your application logs to confirm the arguments are being passed correctly. You should see the same behavior as running java -jar myapp.jar --zk localhost:2020 --uri localhost:1919 directly.
内容的提问来源于stack exchange,提问作者Bambus

