Author Topic: compiling java program with multiple files on a Z  (Read 4798 times)

cascadefx

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://
compiling java program with multiple files on a Z
« on: September 08, 2004, 03:31:38 pm »
I have been trying like crazy to compile a simple two file java program on a 5600.  One file calls a class defined in the other.  The non dependent java file compiles withou problems but the other is a pain and won't work.  I think I have everything set up ande called correctly, but it chokes using both the kopi and jikes compiler.  Here is the code:

sample.java
Code: [Select]
class Sample{
    public static void main(String[] arguments){
  int height;
  int width;
  int depth;
    }
}

usesample.java
Code: [Select]
class UseSample {
    public static void main(String[] arguments) {
        Sample sampling = new Sample();
        sampling.height = 72;
        sampling.weight = 1000;
        sampling.depth = 420;
        System.out.println("Height: " + sampling.height);
        System.out.println("Weight: " + sampling.weight);
        System.out.println("Depth: " + sampling.depth);
    }
}

Any help would be appreciated.

Also, I do realize that programming on the Zaurus isn't ideal, but it is fun and allows me to learn during meetings, bus rides, and car trips.

thanks
Zaurus SL-5600
Sharp 1.0 ROM
256 SanDisk Secure Digital Card (fat16)
Linksys WCF12 wireless card

cascadefx

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://
compiling java program with multiple files on a Z
« Reply #1 on: September 10, 2004, 12:27:28 pm »
Never mind.  I found it.

It was actually a combination of two problems.

Being lazy, I have a template.java file that looks something like this:

Code: [Select]
class CLASSNAMEHERE{
     public static void main(String[] arguments){

      }
}

I used it to create both sample.java and usesample.java.

So my sample looked like this:

Code: [Select]
class Sample{
public static void main(String[] arguments){
 int height;
 int width;
 int depth;
}
}

This is the offending line:

public static void main(String[] arguments){

since I have the main section defined in both files, I caused myself a world of headaches.

Changing the files to be:

sample.java
Code: [Select]
class Sample{
  int height;
  int width;
  int depth;
}

usesample.java
Code: [Select]
class UseSample {
    public static void main(String[] arguments) {
        Sample sampling = new Sample();
        sampling.height = 72;
        sampling.weight = 1000;
        sampling.depth = 420;
        System.out.println("Height: " + sampling.height);
        System.out.println("Weight: " + sampling.weight);
        System.out.println("Depth: " + sampling.depth);
    }
}

fixed my problem partially.

The jikes compiler on the zaurus using the rt.jar libraries compiled these fine.  I first compiled the sample.java file and THEN usesample.java so that the Sample.class would be available for the other to use.  No other tricks necessary.  The problem, at least my problem with jikes is that it (or I) appear to be missing some math libraries (with rt.jar and pj.jar) making it difficult to use for some programs (this isn't one of them).  Kopi doesn't seem to have this limitation, but perhaps I'm doing something wrong.

However Kopi would choke if I compiled the "fixed" program above complaining that it couldn't find Sample even when the Sample.class was in the same directory as the usesample.java file.  No amount of messing with the CLASSPATH either in the environment variables or through the compile time command line seemed to fix the problem.

It finally occured to me to compile both programs with kopi at the same time ala:

Code: [Select]
evm -cp /mnt/cf/kjc-suite.jar at.dms.kjc.Main -C/mnt/cf/gclasses.zip sample.java usesample.java
I actually have the command line in a script file named javac:

Code: [Select]
#!/bin/bash

evm -cp /mnt/card/java/kjc-suite.jar at.dms.kjc.Main -C/mnt/card/java/gclasses.zip $@

So I can compile these files with this call

Code: [Select]
javac sample.java usesample.java
That seems to work.  Problem solved for now.
Zaurus SL-5600
Sharp 1.0 ROM
256 SanDisk Secure Digital Card (fat16)
Linksys WCF12 wireless card

jfox

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://FoxFrenchTranslations.com/zaurus
compiling java program with multiple files on a Z
« Reply #2 on: June 21, 2005, 12:57:56 am »
When compiling several files that reference each other, you must include the working directory in the classpath, so, with Kopi

evm -cp /mnt/card/java/kjc-suite.jar at.dms.kjc.Main -C/mnt/card/java/gclasses.zip:. $@

note the added ":." on Kopi's classpath parameter.

You must do something similar if using Jikes or javac.