[Mono-list] Java Problem

Jonathan Pryor jonpryor at vt.edu
Wed Sep 28 06:58:10 EDT 2005


On Wed, 2005-09-28 at 13:16 +1000, mono-list.1.tracyanne at spamgourmet.com
wrote:
> When I attempt to create a Java project and compile it, I get the
> following error.
> 
> [Task:File=, Line=-1, Column=-1, Type=Error, Description=Error: file not
> found: *.class
> 
> This is the code generated by Glade# Java project
> 
> /*
>  * application.java
>  *
>  * created on 28/09/2005 at 11:47
>  */
> import cli.Gnome.*;
> import cli.Gtk.*;
> 
> public class application {
>     public static void main (String[] args) {
>         Program p = new Program ("Name", "0.0", Modules.UI, args);
> 		App app = new App ("Hello Mono with Java#", "0.0");
> 		Button b = new Button ("Click me");
> 		app.Add (b);
> 		app.ShowAll ();
> 		p.Run ();
>     }
> }

I don't know what you need to do for MonoDevelop, but for the command
line you'd need to do this:

	# Create .jar stubs for javac/gcj to find for managed libraries.
	$ mono ikvmstub.exe /usr/lib/mono/1.0/mscorlib.dll
	$ for f in /usr/lib/mono/gtk-sharp/*.dll ; do \
		mono ikvmstub.exe $f ; 
	  done

	# Edit application.java:
	# (1) Properties are just methods, and Java requires that you 
	#     invoke the underlying methods
	# (2) That Program constructor doesn't exist
	# So replace:
	#    Program p = new Program ("Name", "0.0", Modules.UI, args);
	# with:
	#    Program p = new Program ("Name", "0.0", Modules.get_UI(), args, null);

	# Compile application.java.  I'm using FC4's GCJ:
	$ export MY_CP=gtk-sharp.jar:gnome-sharp.jar:glib-sharp.jar:atk-sharp.jar:mscorlib.jar
	$ gcj -C --CLASSPATH=$MY_CP application.java

	# Run the program, either using (1) ikvm.exe, or 
	# (2) ikvmc.exe + mono

	# (1) ikvm.exe:
	$ mono ikvm.exe -cp $MY_CP application

	# (2) ikvmc.exe + mono
	# ikvmc.exe makes a .exe from a .class which mono can run.
	$ mono ikvmc.exe `pkg-config --libs gtk-sharp gnome-sharp` \
	  application.class
	$ mono application.exe

And that's it.  That and watching one computer halt and catch fire when
running application.exe, and another computer generate a
java.lang.NullPointerException when running application.class (methinks
passing `null' as the final Program parameter might not be a good idea,
but I don't care enough to actually debug further).

Running the sample Java+Gtk# demo from
http://tirania.org/blog/texts/gtkjava.html works correctly.

One final word of warning: Mono+IKVM uses GNU Classpath for the Java API
implementation.  It cannot and will not use your JRE-provided libraries.
Consequently, you *can* compile your code with the JRE compiler, but
your code may not *run* under IKVM, as you may be using unimplemented
portions of GNU Classpath.  I'd suggest using gcj when compiling since
it also uses GNU Classpath, but that's just me.
Be careful. :-)

See also http://www.ikvm.net, the IKVM tutorial, and #mono on IRC.

 - Jon




More information about the Mono-list mailing list