4

I am trying to use mojo keytool API from codehaus - http://mojo.codehaus.org/keytool/keytool-api/index.html

I have set up a sample project and just trying to perform changeAlias request through API.

Here is my sample code:

KeyToolChangeAliasRequest request = new KeyToolChangeAliasRequest();
request.setVerbose(true);
request.setKeystore("keystore.ks");
request.setStorepass("keypass");
request.setAlias(oldAlias);
request.setKeypass("keypass");
request.setDestalias(newAlias);

DefaultKeyTool keyTool = new DefaultKeyTool();
JavaToolResult result = keyTool.execute(request);
result.getExitCode();
result.getExecutionException();

However, when I run the programme I am getting null pointer exception -

java.lang.NullPointerException
at org.codehaus.mojo.keytool.DefaultKeyTool.createCommandLine(DefaultKeyTool.java:53)
at org.codehaus.mojo.keytool.DefaultKeyTool.createCommandLine(DefaultKeyTool.java:33)

Because of the poor documentation, I am not able to find how to use the API correctly.

gvlasov
  • 18,638
  • 21
  • 74
  • 110
Onkar
  • 45
  • 4

1 Answers1

2

You can't use the code that way. It must be done in a plexus container environment.

You can see where the code is breaking (http://mojo.codehaus.org/keytool/keytool-api/xref/org/codehaus/mojo/keytool/DefaultKeyTool.html#53) that the builder object is null, since it should be injected via the plexus container.

If you want we could discuss about improve the code to be more easely called from outisde (please if you can use the project users or devel mailing-list).

Tony Chemit
  • 1,175
  • 4
  • 14
  • 30
  • Thanks tony for replying. My requirement is to execute keytool commands from java and I was hoping if I could leverage mojo API. Yes, we can discuss about improving the code to be easily called from anywhere, but for now I think I will be sticking with java.security.* classes. – Onkar Feb 17 '15 at 06:47