How to Compile a JSyn Program
JSyn is provided in a JAR file. To use JSyn with your program simply add the JSyn JAR file to your classpath.
You can compile simple Java JSyn programs from the command line. But we highly recommend using Eclipse. Eclipse is a free and powerful development environment for Java.
Compiling from the Command Line
You can compile your program with JSyn from a shell. Here is an example of how to compile code in a folder called "com/mystuff" and to place the results in a folder called "classes". Assume the JSyn JAR file is called "jsyn_16_7_0.jar"
javac -d classes -cp pathtojar/jsyn_16_7_0.jar com/mystuff/*.java
Using JSyn in an Eclipse Project
We highly recommend using Eclipse for Java development. Eclipse is a free IDE with an editor, compiler and debugger. Eclipse has powerful "refactoring" tools that let you reorganize code and do smart global renaming.
If you are already an Eclipse expert, just put the JSyn examples in your project folder and then add the JSyn JAR file to your Build Path. If you are new to Eclipse, then please read on for more detailed instructions.
If you haven't already installed Eclipse then get it from here.
Prepare for JSyn
- If you used JSyn before or installed the old JSyn plugin, then remove those old JSyn JAR files. Look in these folders on Macintosh:
- {your hard drive}/Library/Java/Extensions/*jsyn*
- {your username}/Library/Java/Extensions/*jsyn*
- Download the latest JSyn JAR file.
- Download the JSyn Examples archive.
- Download the jsyn-javadocs.jar file.
Create a JSyn Project.
- Launch Eclipse.
- From the File menu, select "New" then "Project...".
- Select the type "Java Project" Wizard and click "Next>".
- Give your project a name like "JSynFun".
- Click "Finish" button to create the project.
Add JSyn JAR to Eclipse CLASSPATH
- Open the "workspace/JSynFun" folder using Finder on Mac or Explorer on Windows.
- Create a new "libs" folder in the JSynFun project folder and put the JSyn JAR file in the "libs" folder.
- In Eclipse, right click on the "JSynFun" folder and select "Refresh".
- In Eclipse, open the libs folder and right click on the JSyn JAR file. Select "Build Path" / "Add to Build Path".
Add JSyn JavaDocs to Eclipse (Optional)
If you attach javadocs to the JAR file in Eclipse then you can get popup documentation.
- Open the "workspace/JSynFun/libs" folder using Finder on Mac or Explorer on Windows.
- Create a new "docs" folder in the "libs" folder and put the jsyn-javadocs.jar file in the "docs" folder.
- In Eclipse, right click on the "JSynFun" folder and select "Refresh".
- In Eclipse, open the libs folder and right click on the JSyn JAR file. Select "Build Path" / "Configure Build Path".
- Click on the "Libraries" tab.
- Click on the triangle next to the JSyn JAR file so that it displays several lines below it.
- Double click on the "Javadoc location" line.
- Select "Javadoc in Archive".
- Select "Workspace file".
- Click on the "Browse..." button and select the "libs/docs'jsyn-javadocs.jar" file.
- Click "Validate..." to test it.
- Click "OK" until you are back to the Eclipse workspace.
Add JSyn Examples, Compile and Play
- Open the "workspace/JSynFun/src" folder using Finder or Explorer.
- Unpack the JSyn examples archive.
- Drag the "com" folder from the examples archive into the "src" folder of your Eclipse project.
- In Eclipse, right click on the "src" folder and select "Refresh".
- In Eclipse, double-click the "com.jsyn.examples.PlayTone.java" file.
- Under the Eclipse "Run" menu select "Run As" / "Java Application".
- You should hear a tone.
- Read the docs and start writing some real "computer music".