构建 GWT 应用程序的最佳方法

发布于 2024-12-06 11:40:02 字数 109 浏览 0 评论 0原文

将 GWT 应用程序构建到 .war 文件的最佳方法是什么?

我已经有一个 ant 文件来构建我的项目,但是,它非常丑陋且缓慢。我认为你们中的一个人有更好的选择...

谢谢

What is the best 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牛↙奶布丁 2024-12-13 11:40:02

我个人使用maven,但是嘿,每个人都有自己的。 (至少你没有使用Makefile)。

然而,编译 GWT 应用程序会很慢。 GWT编译器需要为常见的浏览器类型编译多种风格的javascript,即使是google工程师也无法影响物理定律(也许在下一个版本的guava中)。

我的项目编译了 6 个单独的迭代,并产生了 40MB 的战争。优点是一旦我陷入战争,Tomcat 的性能就击败了托管模式的性能。

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.

日暮斜阳 2024-12-13 11:40:02

使用行家。它经过验证并通常用于构建 java 和 GWT 项目。

http://maven.apache.org/

您应该使用 GWT maven 插件:http://mojo.codehaus.org/gwt-maven-plugin/

但您应该注意:GWT 构建是总是很慢(取决于代码 数量)。因此,您必须仅将完整构建用于生产目的。在 Maven 中,您只能运行特定的子任务并可以添加配置文件。有关更多信息,请阅读插件文档

UPD:

因此,您必须仅将完整构建用于生产目的。

事实并非如此。但对于常见的开发过程,您不需要每次都运行 GWT 编译。当您在调试模式下运行 GWT 时,它会在托管模式下运行。因此您不必浪费时间进行频繁的重建。

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.

固执像三岁 2024-12-13 11:40:02

我创建了一个比以前更好的 ant 构建,完整的代码是:

<?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>

它需要在 war 文件夹中一个名为“server_resources”的文件夹。
这个解决方案对我来说非常有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文