I have made a java program that synthesises sounds using the MIDI package in the java sound API, however, when I export it to a .jar file, the sound played is quite different to what it is when I run it in eclipse. Does anyone know why it is doing this or how to fix this problem?
A list of the instruments can be found here: http://www.hittrax.com.au/images/artists/gmgs.pdf
Below is a section of my code
try {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
MidiChannel[] channels = synth.getChannels();
channels[0].programChange(123); // Set the instrument to be played (integer between 0 and 127)
channels[0].noteOn(60, 80); // Play Middle C
Thread.sleep(duration);
channels[0].noteOff(60);
Thread.sleep(500);
synth.close();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
The image below shows the audio when I record it, the first one is what the sound should be as on eclipse, the second one is what the sound is when exported to a .jar

As you just found out Java returns different default synthesizer when running the jar file outside of eclipse.
This might be caused by the
javax.sound.midi.Synthesizerproperty or asound.propertiesfile in the classpath.As a workaround you could print the property value when running the application inside of eclipse and set it manually so the jar file uses the same synthesizer.
Edit:
If you want to use
com.sun.media.sound.MixerSynthas default create the propertyExample:
More information: http://docs.oracle.com/javase/7/docs/api/javax/sound/midi/MidiSystem.html)