I am relatively new to TeaVM and overall converting to webassembly. I have created Java 11 library which is meant to be used for calculations - so far it has one Core module which consist of logic used for calculations. I want to convert this java library to webassembly (.wasm file) so it can be used on frontend (React app).
I have found TeaVM that can compile my java code to this format. I followed these steps:
- Add TeaVM dependency and configuration to my Maven pom.xml
- Annotated function with @Export(name="nameOfFunction")
- Run mvn clean package
Next, I wanted to make sure that function has been added so I opened generated .wasm file here and tried to look for function name but did not succeeded so I guess it has not been added then.
Are there any additional steps required in order to achive .wasm file generated using TeaVM please? Thanks for any help
This is part of my pom.xml related to TeaVM:
// rest of pom.xml
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<targetDirectory>${project.build.directory}/webapp/wasm</targetDirectory>
<targetFileName>complexlogic.wasm</targetFileName>
<targetType>WEBASSEMBLY</targetType>
<optimizationLevel>FULL</optimizationLevel>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This is function I am trying to export (it is just an example so it is just easy calculation):
import org.teavm.interop.Export;
// rest of code
@Export(name = "getMagicNumber")
public int getMagicNumber(int range) {
return range * 2;
}
// rest of code