[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: No VM02 at KFest?
On Jul 22, 9:51 pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
> In article
> <f585a368-ca9f-4396-a18d-b9f646347...@b4g2000pra.googlegroups.com>,
>
>
>
>
>
>
>
> DaveSchmenk <dschm...@gmail.com> wrote:
> > On Jul 22, 5:23 pm, dog_...@macgui.com (D Finnigan) wrote:
> > > DaveSchmenk wrote:
> [...]
> > > I was compiling some things for it, but got stuck with what I think
> > > is a javac problem. I can't figure out how to compile a single
> > > .java file with multiple classes into just one file. It seems like
> > > VM02 wants everything in one file, but maybe that's not the case,
> > > either.
>
> > You just need to specify where the classes are - no need to build one
> > huge class file. VM02 just can't handle .jar files. Look how the
> > samples include the classes for the gui and apple2 classes, i.e.:
>
> > import apple2.*;
> > import org.vm02.cui.*;
>
> > When javac goes traipsing through the directories looking for
> > the .class files, it will build them from the .java source if it
> > doesn't find them. In my makefile (I'm the worst makefile author in
> > the world) I try to build all the class files up front so that I can
> > copy them to ProDOS image directory. I've had a few bugs when javac
> > would update a class file before the makefile got to it so it never
> > got copied to the ProDOS image. Arrggghhh.
>
> > Drop me a line if you need more info.
>
> > Dave...
>
> I couldn't see a way to do nested classes; ProDOS rejects the filename.
> Alternatively, "a single source file may declare any number of classes,
> but only one may be public."
>
> <http://stackoverflow.com/questions/2366531>
>
> For example,
>
> import apple2.*;
>
> public class Main {
>
> public static void main(String args[]) {
> System.out.println("Hello, world!");
> System.out.println("Answer: " + Answer.n);
> }
>
> }
>
> class Answer {
> static int n = 42;
>
> }
>
> You have to copy both classes to the destination:
>
> DISK=java.2mg
> CLASSPATH=.:/Users/Shared/vm02/src
>
> Main: Main.java
> javac -cp ${CLASSPATH} Main.java
> ac -d ${DISK} Main
> ac -p ${DISK} Main bin < Main.class
> ac -d ${DISK} Answer
> ac -p ${DISK} Answer bin < Answer.class
>
> Oddly, if I put both classes in a subdirectory, Main runs, but the vm
> looks for Answer in the root directory.
>
> --
> John B. Matthews
> trashgod at gmail dot com
> <http://sites.google.com/site/drjohnbmatthews>
This has to do with the way Java saves the class name and the way VM02
searches for classes. VM02 doesn't have a concept of CLASSPATH except
from where vm02 was started. The easiest way around this is to use
packages for your projects. In your case, put the .java files in a
subdirectory /Users/Shared/vm02/src/answer and use
package answer;
at the beginning of your .java files. Insert the files into the
answer directory in the ProDOS image file instead of the bin
directory. Now everything will line up with the directories and live
nicely off the main vm02 directory. You can easily use classes in
other packages with an import statement. You can see where I use the
recommended reverse URL naming scheme for local packages with the CUI
class (org/vm02/cui then importing org.vm02.cui.*).
If the class generated class name is too long for ProDOS, just
truncate it when importing into the ProDOS image. If the unique part
of the filenames come after the truncation part, you will have to
shorten the base name of the class. Sorry, I just couldn't find an
easy way around this.
Dave...