4

I want to run javap command from an ant script. Javap command is located in the bin folder under JDK, but how do I access the JDK path in an ant script? ${java.home} is pointing to the JRE instead of JDK, so that doesn't help.

I'm, looking for a solution which does not require any configuration to the system such as modifying PATH or setting other environment variables like JAVA_HOME. A solution that works only in Windows is fine.

msell
  • 2,168
  • 13
  • 30

2 Answers2

2

Ant scripts can read external properties file. A simple solution would be to add a JDK_HOME property to your existing property file or your Ant script. After that, you can just refer to the javap tool using JDK_HOME as a reference. This solution doesn't require you to change any system property; the only requirement here is that you need to know the JDK path.

Sanjay T. Sharma
  • 22,857
  • 4
  • 59
  • 71
  • My problem is how to get the JDK path programmatically in the first place – msell Dec 13 '10 at 07:56
  • @msell: Unless the JAVA_HOME itself is not JDK_HOME, there is no sane way of finding out *where* the JDK is installed. A more fitting question would be, can we assume the JDK will always be installed? An ad-hoc solution would be to *search* the file system for a file called `javap.exe` but I'm sure you already know the kind of mess this would ensue. :-) – Sanjay T. Sharma Dec 13 '10 at 08:36
1

First, thank you for the question. I did not know about this utility and always used external tools like DJ or JAD for decompilation.

Second, I do not believe that you have an easy way. I am affraid that you have to create your own platform specific mechanism that locates JDK. Use registry for windows and command linke like

ls /bin/java*/bin/javac* | tail -1 

on unix.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • `javap` is much more than your standard decompiler; look into the various switches provided by `javap` and you would be amazed. :-) – Sanjay T. Sharma Dec 13 '10 at 07:49