Help - Search - Members - Calendar
Full Version: compiling java program with multiple files on a Z
OESF Portables Forum > General Forums > General Discussion
cascadefx
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
class Sample{
    public static void main(String[] arguments){
 int height;
 int width;
 int depth;
    }
}


usesample.java
CODE
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
cascadefx
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
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
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
class Sample{
 int height;
 int width;
 int depth;
}


usesample.java
CODE
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
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
#!/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
javac sample.java usesample.java


That seems to work. Problem solved for now.
jfox
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.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2019 Invision Power Services, Inc.