How do i compile a multi source application?

This may be a really stupid question but im trying to make space invaders, but im used to single source applets, this has many source files.

I try by changing drive to the folder then compiling the main source file , Game.java.

This says error cant find class SpriteStore, etc because they havent been created, and i cant create them as they are interdependent.

I read that javax.swing should automatically compile all defined classes also but this is not the case.

How would i generate all the class files?

Have looked around for ages so i thought i would ask, would really appreciate your help :slight_smile:

If you are using javac directly form the command line, did you specify your source directory with -sourcepath?
Did you read the documentation for javac?

[quote]I read that javax.swing should automatically compile all defined classes also but this is not the case.
[/quote]
The swing package has nothing to do with compiling anything. I think you misunderstood something.

[quote]How would i generate all the class files?
[/quote]
I would recommend using Ant (http://ant.apache.org/). But starting with the javac documentation should help.

Once you have that working it is probably a good idea to start using an IDE such as NetBeans or Eclipse.

Yes, use an IDE such as Eclipse or NetBeans! Do NOT use a text editor …

Thanks for the help :),
ive now read through it but its generating a class file of 0 bytes im following this;

Example - Two Arg Files
You can create two argument files – one for the javac options and the other for the source filenames: (Notice the following lists have no line-continuation characters.)

Create a file named “options” containing:

 -d classes
 -g
 -sourcepath \java\pubs\ws\1.3\src\share\classes

Create a file named “classes” containing:

 MyClass1.java
 MyClass2.java
 MyClass3.java

You would then run javac with:

C:> javac @options @classes

my files are options;
-d classes
-g
-sourcepath \SpaceInvaders\org\newdawn\spaceinvaders

and classes;
AlienEntity.java
SpriteStore.java
and the others.

both saved in spaceinvaders then i open command prompt go to batch file then change drive to spaceinvaders folder
and type c:> javac @options @classes
This generates a class file of 0 kb called javac.

What am i doing wrong ? :-\

i also read this but dont understand whether i type this straight on the command line as i tried but didnt work;

Compiling Multiple Source Files

This example compiles all the source files in the package greetings.

    C:> dir
    greetings\
    C:> dir greetings
    Aloha.java         GutenTag.java      Hello.java         Hi.java
    C:> javac greetings\*.java
    C:> dir greetings
    Aloha.class         GutenTag.class      Hello.class         Hi.class
    Aloha.java          GutenTag.java       Hello.java          Hi.java

i know the package is org.newdawn.spaceinvaders. Sorry for being usless ;p.

I think you’re confusing yourself with all that option file stuff.

Ok, say you unzipped the class files into c:\SpaceInvaders. This is your base directory for compiling and running the program. Go into this directory and run the following commands:

To compile: javac org/newdawn/spaceinvaders/*.java
To run: java -cp . org.newdawn.spaceinvaders.MainClass (substitute the name of the class with main in it for MainClass)

The “-cp .” option tells java to use the current directory as a base to look for the class files.

Cheers,
Brett

yay i tried and it didnt work so i downloaded like a new version from here ; http://www.cokeandcode.com/node/8
and it worked but they defined a class AdvancedTimer ( import com.dnssalias.java.timer.AdvancedTimer; )
That compiler says doesnt exist so i have 4 errors.
Could they have a different jdk to me?
I have j2eesdk-1_4_03 .

Also not sure why the original folder wouldnt compile, but new one has more files in it like .classpath.
Thanks for the help though you guys are cool. :slight_smile:

*Have now made old version work.

DOS Java Project Example how to structure folders and files.
http://koti.mbnet.fi/akini/java/dosproject/

Im trying to run it now from the same folder , the first one in from c:, the same one i compiled it from, im typing java -cp.org.newdawn.spaceinvaders.Game.class (also tried .Game without .class) and it says unrecognised option could not create the virtual machine.

Also tried running it from a html but just said applet not initialised.

not sure what to do, also tried cd to the class file folder and java Game.class also didnt work( not class def found error even though its there with 6kb this time with all the others.

leave a space after the -cp and no dot!

java -cp org.newdawn.spaceinvaders.Game

sorry doesnt work :-\

the file structure is c:\spaceinvaders\org\newdawn\spaceinvaders

im in the first space invaders and my Path is my bin, my Classpath is the default as my batch file is

cd C:\sun2\appserver\jdk\files
Path= sun2\appserver\jdk\bin
set CLASSPATH=

Heres the folder ( its Rared ) if you can get it to work you are a genius.( more likely i am a fool )

http://www.uploadtemple.com/view.php/1143382968.rar

Dont worry ive fixed it now , i did same thing as before and it magically worked
( java org.newdawn.spaceinvaders.Game)

making my version now from scratch- garden invaders

Thanks for all the help you guys rule :slight_smile: