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.

Error: NoClassDefFoundError when using Eclipse to run COMSOL model

Please login with a confirmed email address before reporting spam

Hi! I am trying to use Eclipse to run a COMSOL model and I have read the guide from programming reference manual. However, Eclipse always report the error as follows,

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter at com.comsol.client.interfaces.b.<init>(SourceFile:60) at com.comsol.client.interfaces.b.<init>(SourceFile:39) at com.comsol.clientapi.engine.APIEngine$c.b(SourceFile:497) at com.comsol.clientapi.engine.APIEngine.a(SourceFile:115) at com.comsol.clientapi.engine.APIEngine.connect(SourceFile:98) at com.comsol.clientapi.engine.APIEngine.connect(SourceFile:87) at com.comsol.clientapi.engine.ClientModelUtil.connect(SourceFile:145) at com.comsol.clientapi.engine.ClientModelUtil.connect(SourceFile:133) at com.comsol.model.util.ModelUtil.connect(SourceFile:248) at PFCZM_3PBending_QuasiBrittle.main(PFCZM_3PBending_QuasiBrittle.java:16750) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ... 10 more

I believe I have imported the JAR files correctly and set the path for the project and it seems that the error is due to lack of source file for COMSOL API JAR files. I have checked those JAR file and found they are indeed all class files without definition. How can I solve this problem? Thanks!


2 Replies Last Post 2021年8月1日 GMT-4 05:00

Please login with a confirmed email address before reporting spam

Posted: 3 years ago 2021年8月1日 GMT-4 04:57

Hello John,

What path did you use for importing the JAR? On my installation it is /path/to/comsol/plugins/ If the path is pointing to the correct JAR, you should notice that immediately because Eclipse will recognise the imported objects and successfully check the signatures of the imported functions. Otherwise, you would get many warnings in the editor.

I remember struggling with this too. In the end, I opted to compile COMSOL models with a shell script. Assuming you're on Linux, this script should work pretty well for you too:

# !/usr/bin/bash
# COMSOL compilation
# Place this script in the main directory of your java project
SRC_FOLDER="./src/"  # folder containing the java sources
BIN_FOLDER="./bin/"  # folder where class files should be saved
JAR_FOLDER="/path/to/comsol/plugins/"  # comsol jar files location

# Get the list of  source files 
SRC_LIST=$(find $SRC_FOLDER -type f | grep "\.java$")

# Get the list of plugins
JARS = $(find $JAR_FOLDER -type f | grep "\.jar$")
CLASSPATH=$(echo $JARS | tr ' ' ':')

# Debug:
# echo "CLASSPATH:"
# echo "$CLASSPATH"

# Create the output directory if does not exist already
mkdir $BIN_FOLDER 2>/dev/null

# Run the compilation
echo "Compiling to $BIN_FOLDER ..."
javac -cp $CLASSPATH -d $BIN_FOLDER $SRC_LIST
echo "Done."
Hello John, What path did you use for importing the JAR? On my installation it is /path/to/comsol/plugins/ If the path is pointing to the correct JAR, you should notice that immediately because Eclipse will recognise the imported objects and successfully check the signatures of the imported functions. Otherwise, you would get many warnings in the editor. I remember struggling with this too. In the end, I opted to compile COMSOL models with a shell script. Assuming you're on Linux, this script should work pretty well for you too: # !/usr/bin/bash # COMSOL compilation # Place this script in the main directory of your java project SRC_FOLDER="./src/" # folder containing the java sources BIN_FOLDER="./bin/" # folder where class files should be saved JAR_FOLDER="/path/to/comsol/plugins/" # comsol jar files location # Get the list of source files SRC_LIST=$(find $SRC_FOLDER -type f | grep "\.java$") # Get the list of plugins JARS = $(find $JAR_FOLDER -type f | grep "\.jar$") CLASSPATH=$(echo $JARS | tr ' ' ':') # Debug: # echo "CLASSPATH:" # echo "$CLASSPATH" # Create the output directory if does not exist already mkdir $BIN_FOLDER 2>/dev/null # Run the compilation echo "Compiling to $BIN_FOLDER ..." javac -cp $CLASSPATH -d $BIN_FOLDER $SRC_LIST echo "Done."

Please login with a confirmed email address before reporting spam

Posted: 3 years ago 2021年8月1日 GMT-4 05:00

Note that you must change the definitions of SRC_FOLDER, BIN_FOLDER and JAR_FOLDER to match your situation.

Note that you must change the definitions of `SRC_FOLDER`, `BIN_FOLDER` and `JAR_FOLDER` to match your situation.

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.