Error when loading a class (cheerpjRunLibrary)

This is my first time using CheerpJ, so I'm sure it's a silly mistake on my part... As you can see in the console output in the picture, my library successfully loads, but then the class fails to load. This is my js code:
try {
console.log("initializing")
await cheerpjInit()
console.log("initializing done")
} catch (e) {
console.log("initializing failed")
throw e
}

try {
console.log("loading jar file")
lib = await cheerpjRunLibrary("/app/cheerpjtest/target/cheerpjtest-1.0-SNAPSHOT.jar")
console.log("loading jar file done")
} catch (e) {
console.log("loading jar file failed")
throw e
}

try {
console.log("loading class")
MyClass = await lib.com.example.MyClass
console.log("loading class done")
} catch (e) {
console.log("loading class failed")
throw e
}
try {
console.log("initializing")
await cheerpjInit()
console.log("initializing done")
} catch (e) {
console.log("initializing failed")
throw e
}

try {
console.log("loading jar file")
lib = await cheerpjRunLibrary("/app/cheerpjtest/target/cheerpjtest-1.0-SNAPSHOT.jar")
console.log("loading jar file done")
} catch (e) {
console.log("loading jar file failed")
throw e
}

try {
console.log("loading class")
MyClass = await lib.com.example.MyClass
console.log("loading class done")
} catch (e) {
console.log("loading class failed")
throw e
}
The directory structure:
.
├── cheerpjtest
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── cheerpjtest
│ │ └── MyClass.java
│ └── target
│ └── cheerpjtest-1.0-SNAPSHOT.jar
└── index.html
.
├── cheerpjtest
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── cheerpjtest
│ │ └── MyClass.java
│ └── target
│ └── cheerpjtest-1.0-SNAPSHOT.jar
└── index.html
The pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>cheerpjtest</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>cheerpjtest</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
And the java file
package com.example;

public class MyClass {
public static int timesTwo(int n) {
return n * 2;
}
}
package com.example;

public class MyClass {
public static int timesTwo(int n) {
return n * 2;
}
}
I would appreciate any help!
No description
1 Reply
koork
koorkOP2mo ago
Solved! It was a silly mistake. java.lang.UnsupportedClassVersionError because I compiled it with Java 17, but CheerpJ is set to Java 8 by default.

Did you find this page helpful?