Using jMusic on Windows

This page assumes you have installed Java, the Java SDK (Software development kit) and jMusic. See the install instructions if required.

DOS Prompt

Java programming involves running programs from the command line, or DOS prompt. You can open a DOS window to display the command line by choosing "MS-DOS Prompt" from the "Programs" section of the Windows "Start" menu, or Just type 'cmd' in the run window found under the 'start' menu. Get this running.

Java runner and compiler

The command line allows you to type commands, such as java and javac (the Java compiler). Try typing each of these at the command line and pressing return. Because they are incomplete commands you will get an error message describing the correct usage of the commands. But this will at least prove you have them installed. (The C:> in this text indicates the dos prompt - only type what's after it). Try each of these commands.

C:> java

C:> javac

Changing directories

If you do not get a usage error for javac then it may be best to navigate to the javac directory and work from there. For example, if your Java SDK wa installed in C:\jdk1.4 you would type C:> cd C:\jdk1.4\bin

The command cd is an abbreviation of change directory.

The DOS prompt will change to indicate your current directory location, It may read C:\jdk1.4\bin> but in this page I will always abbreviate it to C:>

This is not a convenient way to get javac to to work. In the next section we'll create a new directory and work from in there. When we do so we can access the javac by explicitly using its full path name.

C:> C:\jdk1.4\bin\javac

Creating directories

Assuming you have a jMusic directory already let's create a folder within that for our Java work. At the prompt type C:> mkdir C:\jMusic\JavaWork

You can follow these changes to directories and files in a Windows Explorer window as you go along to keep a familiar eye on what we're doing here.

Navigate to this new directory, we'll work from here.

C:> cd C:\jMusic\JavaWork

Editing files

To proceed further we need a java file to work with. Java files are simple text files and DOS includes a suitable editor - called edit. To start the editor type C:> edit

Type in this simple Java program.

public class Test {
public static void main(String[] args){
System.out.println("Java works");
}
}

Use the menu commands in edit to save the file to your work directory with the name Test.java, here is the directory path as a reminder - C:\jMusic\JavaWork\Test.java

Use Windows Explorer to look inside the JavaWork folder to make sure the Test file is saved there.

Exit from the editor.

Compiling

The javac command is used for compiling. It needs to know where the file is located, so we specify its classpath.

A hint: You may often need to retype the same commands so there is a program that can recall previously typed commands using the up and down arrow keys. C:> doskey

To compile type C:> C:\jdk1.4\bin\javac Test.java

A file called Test.class should be created in the JavaWork directory.

Running

To run the class file use the java command with a class path and file name. Notice that when running you omit any suffix from the program name.

C:> java -classpath "C:\jMusic\JavaWork" Test

You should see the words Java Works appear at the command line. The System.out.prinln command sends a line of text [a string] to the command line while the program is running.

Adding jMusic

Start edit, and open the file and change it to add these jMusic additions.

import jm.JMC;
import jm.music.data.*;
import jm.util.*;
 
public class Test implements JMC {
public static void main(String[] args){
System.out.println("Java works");
Score s = new Score(new Part(new Phrase(new Note(C4, MINIM))));
Write.midi(s, "Test.mid");
}
}

Save the file. Quit edit. Recompile the class (remember to use the up arrow to save typing). Rerun the program. A MIDI file with one note should be added to your JavaWork directory, and jMusic will print various messages to the command line as it proceeds.

To compile or run you will need to set the classpath to jMusic.

C:> C:\jdk1.3\bin\javac -classpath "C:\jMusic\lib\jmusic.jar" Test.java

C:> java -classpath "C:\jMusic\JavaWork;C:\jMusic\lib\jmusic.jar" Test

Exploring

Now it's time for you to make changes to the program and to practice the edit, compile run cycle.



jMusic Tutorial Index