Introduction
Tooling
Using Maven
The easiest way to run TeaVM is to use teavm-maven-plugin
.
Here is an example of how to use it:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>0.6.1</version>
<dependencies>
<!-- This dependency is required by TeaVM to emulate subset of Java class library -->
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>0.6.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<mainClass>org.teavm.samples.HelloWorld</mainClass>
<mainPageIncluded>true</mainPageIncluded>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The build-javascript
goal
Here is the list of properties supported by the goal:
- mainClass – a fully qualified name of a class that contains the
main(String[])
method. When this property specified, TeaVM producesmain
function in global scope that runs the translated version of the themain(String[])
method in the browser. - targetDirectory – a path to a directory where TeaVM produces all its output.
The default value is
${project.build.directory}/javascript
. - targetFileName – a name of a produced JavaScript file. The default value is
classes.js
. - minifying (
true
|false
) – whether TeaVM should produce minified (obfuscated) JavaScript. The default value istrue
. Minification decreases the size of the generated file two or three times, so it should be preferred in most cases, unless you are going to debug JavaScript manually. However, it is better to debug using source maps or TeaVM eclipse debugger. - debugInformationGenerated (
true
|false
) – whether TeaVM should produce a debug information file for its Eclipse plugin. The default value isfalse
. - sourceMapsGenerated (
true
|false
) – whether TeaVM should produce source maps. The default value isfalse
. - sourceFilesCopied (
true
|false
) – whether TeaVM should copy source files into the output directory. This option is useful in conjunction with the sourceMapsGenerated. TeaVM won’t copy all of the sources, but only sources of classes being decompiled. The default value isfalse
. - incremental (
true
|false
) – whether TeaVM should build JavaScript incrementally. Incremental build speeds up the building process by caching results of some build phases. However, TeaVM is unable to perform several optimizations during incremental build, so this feature is not recommended for production build. The default value isfalse
. - cacheDirectory – a path to a directory that is used to keep cache of incremental builder.
The default value is
${project.build.directory}/teavm-cache
. - classFiles – a path to a directory where TeaVM should take class files produced by Java compiler.
The default value is
${project.build.outputDirectory}
. The default value should be used in most cases. - properties – properties, in standard Maven properties format, that will be passed to the TeaVM builder. These properties are available to TeaVM plugins.
- runtime (
SEPARATE
|MERGED
|NONE
) – how theruntime.js
file should be copied. The default value isSEPARATE
, which means, that theruntime.js
file is copied as a separate file. TheMERGED
value means that the entire body of theruntime.js
file will be copied into the generated JavaScript file, specified by the targetFileName. TheNONE
value means that theruntime.js
file will not be copied at all. - transformers – an array of fully qualified class names.
Each class must implement ClassHolderTransformer
interface and have a public no-argument constructor. These transformers are used to transform
ClassHolder
s, that are SSA-based representation of JVM classes. Transformers run right after parsing JVM classes and producing SSA representation. - optimizationLevel – how strong should TeaVM optimize your code. Following options are supported:
- SIMPLE – perform only basic optimizations, remain friendly to the debugger; recommended for development;
- ADVANCED – perform more optimizations, sometimes may stuck debugger; recommended for production;
- FULL – perform aggressive optimizations; increase compilation time, sometimes can make code even slower; recommended for WebAssembly.
- targetType – what code to generate. Following options are supported:
- JAVASCRIPT
- WEBASSEMBLY
- Previous
- Next