开发者

Best way to build a GWT Application

开发者 https://www.devze.com 2023-04-08 05:43 出处:网络
What is the bes开发者_运维百科t way I can use to build a GWT app to a .war file? I already have one ant file to build my project, but, it is very ugly and slow. I think one of you have a better optio

What is the bes开发者_运维百科t way I can use to build a GWT app to a .war file?

I already have one ant file to build my project, but, it is very ugly and slow. I think one of you have a better option...

thanks


I personally use maven, but hey, to each their own. (At least you're not using a Makefile).

However, compiling a GWT application is going to be slow. The GWT compiler needs to compile multiple flavors of javascript for common browser types, and even the google engineers can't affect the laws of physics (maybe in the next release of guava).

My project compiles 6 separate iterations, and produces a 40MB war. The advantage was once I had it into a war, performance in Tomcat blew away the performance of hosted mode.


Use maven. It's proven and commonly used to build java and GWT projects.

http://maven.apache.org/

You should use GWT maven plugin: http://mojo.codehaus.org/gwt-maven-plugin/

But you should be aware: GWT builds are always slow (depending on code amount). For thus you have to use full build only for production purposes. In maven you can run only specific subtasks and can add profiles. For more info read plugin documentation.

UPD:

For thus you have to use full build only for production purposes.

This is really not so. But for common development process you don't need to run GWT compile each time. When you running GWT in debug mode - it runs in hosted mode. So you haven't to waste your time on often rebuilds.


I create a better ant build than I have before, the complete code is:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Build GPA" basedir="." default="war">

    <property name="gwt.module.name" value="com.geekvigarista.scrummanager.GWT_ScrumManager"/>
    <property name="server.resources.name" value="server_resources"/>
    <property name="jar.name" value="gpa.jar"/>
    <property name="war.name" value="gpa.war"/>
    <property name="src.dir" location="src"/>
    <property name="server.resources.dir" location="war/${server.resources.name}"/>
    <property name="build.dir" location="build"/>    
    <property name="build.server.resources.dir" location="war/WEB-INF/classes/server_resources"/>        
    <property name="lib.dir" location="war/WEB-INF/lib"/>
    <property name="gwt.client.dir" location="com/geekvigarista/scrummanager/client"/>

    <path id="project.classpath">        
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
    </path>  

    <target name="prepare">
        <mkdir dir="${build.dir}"/>
    </target>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>  

    <!-- Compile the java source code using javac -->
    <target name="compile" depends="prepare">        
        <javac srcdir="${src.dir}" destdir="${build.dir}">
            <classpath refid="project.classpath"/>
        </javac>        
    </target>       
    <!-- Invoke the GWT compiler to create the Javascript for us -->
   <target name="gwt-compile" depends="compile">
        <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
            <classpath>
                <!-- src dir is added to ensure the module.xml file(s) are on the classpath -->
                <pathelement location="${src.dir}"/>                
                <pathelement location="${build.dir}"/>
                <path refid="project.classpath"/>
            </classpath>
            <jvmarg value="-Xmx512M"/>
            <arg value="${gwt.module.name}"/>
         </java>
     </target>
    <!-- Package the compiled Java source into a JAR file -->
    <target name="jar" depends="compile">        
        <jar jarfile="${lib.dir}/${jar.name}" basedir="${build.dir}/">
            <!-- Don't wrap any of the client only code into the JAR -->
            <exclude name="${gwt.client.dir}/**/*.class"/>
        </jar>    
    </target>
    <!-- Copy the static server resources into the required 
    directory ready for packaging -->    
    <target name="copy-resources">
        <copy todir="${build.server.resources.dir}" preservelastmodified="true">
            <fileset dir="${server.resources.dir}"/>            
        </copy>
    </target>    
    <!-- Package the JAR file, Javascript, static resources 
    and external libraries into a WAR file -->
    <target name="war" depends="gwt-compile, jar, copy-resources">
        <war basedir="war" destfile="${war.name}" webxml="war/WEB-INF/web.xml">
            <exclude name="WEB-INF/**" />
            <exclude name="${server.resources.name}/**"/>
            <webinf dir="war/WEB-INF/">
                <include name="classes/${server.resources.name}/**" />
                <include name="**/*.jar" />
                <exclude name="**/gwt-dev.jar" />
                <exclude name="**/gwt-user.jar" />
            </webinf>
        </war>
    </target>    
</project>

It needs a folder called "server_resources" in the war folder. This solution works great for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号