Step 1) prepare a java property file with username and password and put togerther with java code
username = xxx
password = xxx
Step 2) Config jenkins job to inject environment variable from property file
Option 1: check Inject environment variables to the build process
under Build Environment
section

Option 2: Add a Inject environment variable
build step and move it to the top on others build steps

For both options, specify the credential property file path relative to jenkins job workspace
Step 3) specify system property: username and password in java cmd line
for example: java -DUserName="${username}" -DPassWord="${password}"
Note:
1. ${xxx}
, the xxx
from the key in property file, case sensitive.
2. Please use double quote in case username or password includes space
3. The pattern -Dxxx="${yyy}"
can work on both Execute linux shell
and Execute windows batch
build step.
More about Java command
Step 4) obtain ssytem property: username and password in Java code
String userName = System.getProperty("UserName")
// the parameter: "UserName" from -Dxxxx, also case sensitive

More about system property