Exact nature of Mendix Java

0
With cloud security off and running off my local machine Mendix seems to inhibit Java in ways I do not understand. If this behavior could be clarified I would appreciate it. Here are crazy examples. For example the following code shows my midi hardware when run outside of mendix: import javax.sound.midi.*; public class A { //public static void main(String[] args) throws IOException { public static void main(String[] args) { MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo(); if (devices.length == 0) { System.out.println("No MIDI dev found!"); } else { for (MidiDevice.Info dev : devices) { System.out.println(dev); } } } } Runs perfectly offline, but put it in Mendix and it says I have no sound device on my machine. Similar strange things happen when I even try instantiating an audiofile: import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; public class A { public static void main(String[] args) throws IOException { double sampleRate = 44100.0; double frequency = 440; double frequency2 = 90; double amplitude = 1.0; double seconds = 2.0; double twoPiF = 2 * Math.PI * frequency; double piF = Math.PI * frequency2; float[] buffer = new float[(int) (seconds * sampleRate)]; for (int sample = 0; sample < buffer.length; sample++) { double time = sample / sampleRate; buffer[sample] = (float) (amplitude * Math.cos((double)piF *time)* Math.sin(twoPiF * time)); } final byte[] byteBuffer = new byte[buffer.length * 2]; int bufferIndex = 0; for (int i = 0; i < byteBuffer.length; i++) { final int x = (int) (buffer[bufferIndex++] * 32767.0); byteBuffer[i] = (byte) x; i++; byteBuffer[i] = (byte) (x >>> 8); } File out = new File("out10.wav"); boolean bigEndian = false; boolean signed = true; int bits = 16; int channels = 1; AudioFormat format; format = new AudioFormat((float)sampleRate, bits, channels, signed, bigEndian); ByteArrayInputStream bais = new ByteArrayInputStream(byteBuffer); AudioInputStream audioInputStream; audioInputStream = new AudioInputStream(bais, format,buffer.length); AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, out); audioInputStream.close(); } } Only in MDX does it not recognize the AudioFileFormat.Type.WAVE How does this work and where can I find out more? Thankyou
asked
1 answers
2

I'm not familiar with making sounds files in Java or Mendix, but I'll try and speak to some common programming challenges you might run into.

The Mendix Platform v5 uses OSGi, this is important to know because this could impact every library and class that you are using in Java. The simplified explanation is: OSGi basically shields your project code and libraries from the code and libraries used by the Mendix Platform.
This allows R&D to make platform changes, and upgrade libraries without causing compile errors in projects. Because every library that is part of the platform is shielded by OSGi, and cannot be access through your custom Java code.

This means that all libraries and classes have to be added to the project, even if the platform already uses it. This makes upgrading easier (because you only have to worry about your own code), but whenever you want to write some Java code and use a library you'll always have to make sure that the library you download is OSGi compatible, and included all dependent libraries too.


I know what to look for and how to resolve OSGi related problems with libraries, but my experience and knowledge with OSGi pretty much stops here. So I'm afraid I can't give you a solution for this. However I have seen more often in other projects that it was difficult or impossible to many of the classes in the javax.* package.

Maybe somebody from R&D can speak to this and explain if this is by design and how to work around this?
(So far I've been able to work around this by not using javax.* and use a completely different library)

answered