Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

importing and compiling multiple custom Java classes to use with COMSOL Java API code

Please login with a confirmed email address before reporting spam

Hello,

I would like to integrate custom Java classes with my COMSOL Java API code. However, I cannot find any recommendation about how to do it using the comsol compile in the documentation.

I would like to ask for further clarification about how to do this.

Let's say I have two files, Main.java and Pair.java. The first file has the main and the COMSOL model. The second file implements a simple class Pair the works similarly to tuple.

Should I compile multiple .java files at once? Should I make a package using a directory containing classes and import them from the main file? Or should make a JAR files? How should I organise file structure and how to use comsol compile to compile?

In the comsol compile -help there is the classpathadd <classpath> option to provide an additional classpath. However, it's not clear how to use it. Could you provide examples of usage please?

Many thanks, Francisco


2 Replies Last Post 2023年3月31日 GMT-4 07:27

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 2023年3月30日 GMT-4 13:25
Updated: 1 year ago 2023年3月30日 GMT-4 13:28

Hello Francisco,

I could be wrong, but in my experience comsol compile will allow you to compile multiple files by comsol compile file1 file2 ..., but either it or comsol batch will still throw errors if you are referencing code from file2 in file1 (unlike if you were to do something similar with javac). I have personally given-up on using more than one class when using COMSOL's java api :(

Regards,

Nathaniel

Hello Francisco, I could be wrong, but in my experience `comsol compile` will allow you to compile multiple files by `comsol compile file1 file2 ...`, but either it or `comsol batch` will still throw errors if you are referencing code from `file2` in `file1` (unlike if you were to do something similar with `javac`). I have personally given-up on using more than one class when using COMSOL's java api :( Regards, Nathaniel

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 2023年3月31日 GMT-4 07:27

Hi,

You can do this, but not without specifying a JDK root such as in this example:

comsol compile -jdkroot /src/java/OpenJDK-8u265/glnxa64/jdk A.java B.java

See the COMSOL documentation for information about -jdkroot and other arguments to the comsol compile command:

https://doc.comsol.com/6.1/docserver/#!search/jdkroot.

We will look into making this task easier to do in a future COMSOL version.

Best regards,

Magnus

Hi, You can do this, but not without specifying a JDK root such as in this example: `comsol compile -jdkroot /src/java/OpenJDK-8u265/glnxa64/jdk A.java B.java` See the COMSOL documentation for information about `-jdkroot` and other arguments to the `comsol compile` command: We will look into making this task easier to do in a future COMSOL version. Best regards, Magnus

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.