Tal Zion
Tal Zion

Reputation: 1441

Maven GWT - Output only Javascript files

I'm trying to generate Javascript from Java files using GWT.
I'm using Maven to build my GWT project but now I'm trying to shorten the Maven build times.
I'm no Maven expert and so I've come here..
It seems Maven is generating .class files from my Java files which I don't think is necessary because I just need the Javascript files and GWT is a source to source compiler.
I don't need any jars, wars or anything else. Just Javascript files.
Here is my POM file:

<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.app</groupId>
<artifactId>webapp</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>org.timepedia.exporter</groupId>
        <artifactId>gwtexporter</artifactId>
        <version>2.4.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>2.7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.7.0</version>

            <executions>
                <execution>
                    <configuration>
                        <webappDirectory>
                            ${WEBAPP_DIRECTORY} 
                        </webappDirectory> 
                    </configuration>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

    <sourceDirectory>src</sourceDirectory>
</build>

Upvotes: 1

Views: 708

Answers (1)

  1. It's ok that maven compiles your .java files and produces .class using javac, that guarantees that your java syntax is correct and that you can use your sources in any IDE. So ignore them.
  2. In order to compile your code to JS, you have to configure maven to execute the GWT compiler, it's done using the gwt-maven plugin. Note that your java code should be compatible with the emulated GWT JRE, so there are some constrains to consider.
  3. Once you have everything working, you will get your JS code in the folder target/artifactId-version/moduleName. You will get all the stuff you need to publish in your webserver. So you will get one module.nocache.js file which is the bootstrap script to load your code, and some MD5.cache.js or MD5.cache.html files depending on what linker you use in your project and the number of permutations you select.
  4. Of course you could collapse all permutations and produce an unique output file if you use the single script linker.

Based on your configuration, it seems you want to export your java api to js using gwt-exporter, you can use jsUpload maven project as reference which is the JS exported version of the gwtupload library written in GWT.

[EDIT]

For a web service producing JS, I will call the compiler directly instead of doing through maven. It will save a lot of the time mvn spends parsing config, checking dependencies, running unneeded tasks, etc. You can simply run maven compile and grab the output of the ps -feawww or take a look to gwt-maven CompileMojo to figure out how to compose the args list. I will consider using draft-mode compilation with incremental option.

Upvotes: 2

Related Questions