compiling java 1.5 code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

compiling java 1.5 code

Adrian Daerr
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It seems impossible to compile Java 1.5 source code (that is, Java code
using language features new to version 1.5) from within ImageJ, even
though ImageJ is running on Java 1.5 or 1.6 (according to its
Properties) and is pointed to the appropriate tools.jar; I have tried on
Linux and MacOS X, and made sure no other Java version was available on
the system.

Did I miss something, or is this a deliberate restriction on the
(depreciated) sun.tools.javac.Main compiler interface used by ImageJ ?
In the latter case, would it be possible to add support for the new
interface javax.tools.JavaCompiler introduced in version 1.6 to replace
the undocumented sun.tools.javac.Main ?

Adrian Daerr

minimal example code:
- ---- snip ----
import ij.plugin.PlugIn;
import ij.IJ;
// "import static" statement new since Java 1.5:
import static java.lang.Math.*;

class CompilerTest implements PlugIn {
  public void run(String arg) {
    IJ.log("sin(1)="+sin(1));// no Math. needed thanks to above
    return;
  }
}
- --- snip ----

Error message:

Note: sun.tools.javac.Main has been deprecated.
/Applications/ImageJ/plugins/Bricabrac/CompilerTest.java:4: Identifier
expected.
import static java.lang.Math.*;
      ^
/Applications/ImageJ/plugins/Bricabrac/CompilerTest.java:8: Method
sin(int) not found in class CompilerTest.
    IJ.log("sin(1)="+sin(1));
                        ^
2 errors, 1 warning
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGI5VDUKl/wQSyHWgRAoQBAJ9munEt6M21tpBm1JfKcNj9hTaviQCggP88
h8mwiwjHSv49f/XH7ShQssk=
=Nzq6
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: compiling java 1.5 code

Albert Cardona
Hi Adrian,

There are several ways to go about it. Here is one:

1) Create your own compiler plugin. You can model it after
ij.plugin.Compiler
2) Edit your IJ_Prefs.txt so that plugin06 (Compile and Run...) will
point to your own plugin and not to the default
ij.plugin.Hotkeys("Compile and Run...").


Here's another:

1) Create your own compiler plugin
2) Create a macro that calls (using macro function call(...); ) a static
setup method on your plugin. Such method has to hack the ij.Menus and
replace the pointer of "Compile and Run..." for your own. This is
trivially done by calling ij.Menus.getCommands() (which gives you a
Hashtable), and replacing the entry.
3) Put the macro to autoexecute on StartupMacros.txt, so that when
ImageJ is launched, you get your command in place.

Now you have your own 1.5-enabled compiler.

Albert