Ashuni
Ashuni

Reputation: 33

Some character are missing when getting properties with : java.lang.System.getProperty();

I'm trying to get value from properties but some of them contains > which seems to cause an issue...

for exemple :

I have 3 tomcat properties

-DTEST_USERNAME=admin

-DTEST_PASSWORD=Pa$$w0rd>

-DTEST_HOST=google.com

the following line :

console.log(java.lang.System.getProperty('TEST_PASSWORD'));

should return : Pa$$w0rd> but insteed return : [console.log]<no source name> - Pa$$w0rd=google.com

is this how it's supposed to work or some kind of issue ? should I change the password to remove the > ?

Additional information : java 8

Link to javadoc : https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getProperty-java.lang.String-

Upvotes: 0

Views: 136

Answers (2)

Ashuni
Ashuni

Reputation: 33

I solved my issue by putting the Pa$$w0rd> in Base64

-DTEST_PASSWORD=UGEkJHcwcmQ+ 

and then decoding the value in javascript with return : Pa$$w0rd>

Upvotes: 0

DuncG
DuncG

Reputation: 15136

The greater than ">" is a file redirection in some terminals / shells. On Windows use double quotes around the definition:

java "-DTEST_PASSWORD=Pa$$w0rd>" ...

On Unix/Gnu/Linux/Bash use single quote or double quote with escaped \$ which avoids having $$ replaced by process id:

java '-DTEST_PASSWORD=Pa$$w0rd>' ...
java -DTEST_PASSWORD='Pa$$w0rd>' ...
java "-DTEST_PASSWORD=Pa\$\$w0rd>" ...

On later JDK versions you can validate that your settings would be passed in correctly by using -XshowSettings:properties parameter. For example, try:

java -XshowSettings:properties "-Dsomeproperty=val>ue" 2>&1 | more

Which should print:

Property settings:
    ...
    someproperty= val>ue

Upvotes: 3

Related Questions