This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: My own problem with gcj



Joshua R. Poulson writes:
> The solution is the command line:
> 
> $ gcj --main=Example -o Example Example.java
> 
> Annoying.

It's a necessary evil, though I'm not sure it is that evil -- I would
consider it being a of great flexibility.  Consider this example made
of two source files:

class a {
  static void fct(String s) { System.out.println (s); }
  public static void main (String[] arg)
  {
    System.out.println ("Running main from class `a'");
    a.fct ("Here");
    b.fct ("There");
  }
}

class b {
  static void fct(String s) { System.out.println (s); }
  public static void main (String[] arg)
  {
    System.out.println ("Running main from class `b'");
    a.fct ("Here");
    b.fct ("There");
  }
}

You can compile both file into object file and at link time you can
choose which main your application will start with:

$ gcj -c a.java b.java
$ gcj a.o b.o --main=a
$ ./a.out
Running main from class `a'
Here
There

$ gcj a.o b.o --main=b
Running main from class `b'
Here
There

a.main() can be the entry point of your application. b.main() can be
the entry point for a stand alone debug or test executable of class b.

./A

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]