Disabling warnings generated by java ant

I use java ant to create certificates and key stores for some objects, which I will use in a java application later. The application is intended only for training, I know that it is a bad idea to store passwords in plain text.

The command I use:

<exec command="keytool -genkey -alias test -keyalg DSA -keysize 1024 -keystore keyst.ks -keypass pass -storepass pass -dname &quot; CN=Duke, OU=MyUnit, O=MyOrg, C=US&quot;"/> 

Although the command works as expected, after each line they give me a couple of warnings:

  [exec] The command attribute is deprecated. 
  [exec] Please use the executable attribute and nested arg elements. 

I am curious if there is a way I can suppress these warnings, except by not using nested arguments. The script generates a lot of text output, and warnings make tracking output difficult.

+4
source share
2 answers

The command attribute in the exec task is deprecated and has been since Ant 1.5 when I first started using Ant. I suspect that it will remain obsolete for quite some time. There is no problem besides the warning, but you can also use the execute attribute, which replaces it.

The only problem is that the execute attribute (as opposed to the command attribute) assumes that the command names can contain spaces, so you cannot just insert the whole command into the execute attribute. Instead, you should use subtesk <arg> to pass parameters to the command:

 <exec executable="keytool"> <arg line="-genkey -alias test -keyalg DSA -keysize 1024 -keystore keyst.ks -keypass pass -storepass pass -dname &quot;CN=Duke, OU=MyUnit, O=MyOrg, C=US&quot;" </exec> 

This last -dname parameter may be a problem. However, you can use the subtask <arg value="> to get around this problem:

 <exec executable="keytool"> <arg value="-genkey"/> <arg value="-alias"/> <arg value="test"/> <arg value="-keyalg"/> <arg value="DSA"/> <arg value="-keysize"/> <arg value="1024"/> <arg value="-keystore"/> <arg value="keyst.ks"/> <arg value="-keypass"/> <arg value="pass"/> <arg value="-storepass"/> <arg value="pass"/> <arg value="-dname"/> <arg value="CN=Duke, OU=MyUnit, O=MyOrg, C=US"/> </exec> 

Note that the parameter for the -dname field no longer needs &quot; Around him. <arg value> understands that this is the only value despite spaces.

You can combine the line and value types of the <arg> subtask:

  <exec executable="keytool"> <arg line="-genkey -alias test -keyalg DSA -keysize 1024"/> <arg line="-keystore keyst.ks -keypass pass123 -storepass pass123 -dname"/> <arg value="CN=Duke, OU=MyUnit, O=MyOrg, C=US"/> </exec> 

At least I have done this without any problems before.

+7
source

Yes, read the warning. Do not use the command attribute; use executable and nested arg elements.

http://ant.apache.org/manual/Tasks/exec.html

So it will look like this:

 <exec executable="keytool"> <arg value="-genkey"/> <!-- I'll leave the rest for you; read the docs --> </exec> 
+3
source

Source: https://habr.com/ru/post/1387942/


All Articles