Instead of using the COMSOL commands for compiling and running a Java® file that uses the COMSOL API one can use an Integrated Development Environment for doing these tasks. Using Eclipse makes it easier to write the Java code because Eclipse has built-in support for code completion and syntax highlighting. Furthermore, the debugger that comes as a part of Eclipse can be used to run the code line by line to verify the function of the code and check for any programming errors. Eclipse is free and can be downloaded from www.eclipse.org. To set up Eclipse for running an exported Java file, perform the following actions in Eclipse:
2 Go to the Libraries tab and click Add External JARs. Add all JAR files placed in the plugins directory under the COMSOL installation directory (typically C:\Program Files\COMSOL\COMSOL52a\Multiphysics). This allows Eclipse to find the definitions of the classes used by the COMSOL API and to run the code in client/server mode. Click Finish.
3 Select the Environment tab. Click the New button. Use the Name PATH (on Windows), LD_LIBRARY_PATH (on Linux), or DYLD_LIBRARY_PATH (on Mac) and enter the following text in Value: <comsolinstalldir>/lib/<platformname>, where <comsolinstalladir> is the directory where COMSOL Multiphysics is installed, and <platformname> is one of win64/glnxa64/maci64 depending on your platform. Click Apply.
4 Drag and drop your exported Java file the src folder of your Eclipse project.
8 You also need to call System.exit(0) at the end of the Java program if ModelUtil.initStandalone() has been called.
9 To run the code you must first start the COMSOL server. When the server has started note the port number that is written in the console. If this number does not match the number written in the call to ModelUtil.connect you have to edit this call and save the file again.