Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling warnings generated by java ant

I'm using java ant in order to generate certificates and keystores for some entities, which I will use in a java app later. The application is for learning purposes only, I know it's a bad idea to store passwords in plain text.

The command that i'm using is :

<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 i'm given a couple of warnings :

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

I'm curious if there is any way that I can surpress these warnings, other than not using nested args. The script generates a lot of text output, and the warnings make it harder to track the output.

like image 694
user852689 Avatar asked Dec 27 '22 08:12

user852689


2 Answers

The command attribute on the exec task has been deprecated and has been since Ant 1.5 when I first started using Ant. I suspect that it will remain deprecated for quite a long time. There's no issue besides the warning, but you might as well use the execute attribute which replaces it.

The only issue is that the execute attribute (unlike the command attribute) assumes that command names can contain whitespace, so you can't simply cram the entire command into the execute attribute. Instead, you must use the <arg> subtesk to pass in the parameters for 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>

That last parameter, -dname might present a problem. However, you can use the <arg value="> subtask 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 it. The <arg value> understands this is a single value despite whitespace.

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

    <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've done that without any issues before.

like image 148
David W. Avatar answered Jan 10 '23 08:01

David W.


Yes, read the warning. Don't use the command attribute; use executable and nested arg elements.

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

So it'd look like this:

<exec executable="keytool">
 <arg value="-genkey"/>
 <!-- I'll leave the rest for you; read the docs -->
</exec>
like image 22
duffymo Avatar answered Jan 10 '23 08:01

duffymo