代码之家  ›  专栏  ›  技术社区  ›  Ittai

使用Ant编译GWT项目时出现问题

  •  5
  • Ittai  · 技术社区  · 16 年前

    我使用GWT已经有一段时间了,到目前为止,我只使用Eclipse插件来编译我的项目。由于新的需求,我需要(第一次)使用Ant构建来构建GWT项目。首先,我会说,我有2个模块,它们有一个入口点和2个其他的普通模块,这些模块只包含Java类(应该转换成JS),它们在我的工作空间中处于不同的项目中。

    目前,我有一个GWT项目,它需要一个公共项目,而这个公共项目又需要DAL项目(当我说“需要”时,我的意思是它在Eclipse项目构建路径中如此定义)。在我的GWT项目中,我在适当的位置有一个common.gwt.xml和dal.gwt.xml文件,它们将这些文件定义为模块,而moduleEntryPoint.gwt.xml继承了这两个模块(以及其他模块)。当我目前使用GWTEclipse插件来编译所有东西时,一切都很好地工作。

    但是,当我尝试用ant build模拟这个过程时,moduleEntryPoint的编译失败,因为编译器说它找不到属于dal模块或公共模块的类的源。

    Ant构建代码非常基础,因为这是我的第一次尝试。
    提前感谢您给予的帮助。

        <path id="compile.classpath">
        <fileset dir="${build.dir.WEB-INF.lib}">
                    <include name="**/*.jar" />
                    <include name="**/*.xml" />
        </fileset>
        <fileset dir="${ExternalLib.WebServer.dir}">
                <include name="**/*.jar" />
                <include name="**/*.xml" />
        </fileset>
    
        <fileset dir="${GWT.dir}">
                <include name="**/*.jar" />
                <include name="**/*.dll" />
        </fileset>
    
    </path>
    
    <target name="clear_previous_war">
    <delete dir="${build.dir}" />
    <mkdir dir="${build.dir.WEB-INF.classes}"/>
    <mkdir dir="${build.dir.WEB-INF.lib}"/>
    

    <target name="build_common" >
        <jar destfile="${build.dir.WEB-INF.lib}/${jar.common}"
            basedir="${common.dir.build}"
            includes="com/**"
            excludes="**/.svn"
          />    
    </target>
    
    <target name="build_dal" >
        <jar destfile="${build.dir.WEB-INF.lib}/${jar.dal}"
            basedir="${dal.dir.build}"
            includes="com/**"
            excludes="**/.svn"
          />    
    </target>
    
    <target name="copy_additional_files" >
        ... Copies all required external jars to web-inf/lib
    </target>
    
    <target name="compile_web_classes" >
        <javac srcdir="src" classpathref="compile.classpath"
        destdir="${build.dir.WEB-INF.classes}"
                source="1.6"/>  
    </target>
    
    <target name="compile_gwt_button"  description="GWT compile to JavaScript">
                    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
                            <classpath>
                                    <pathelement location="${src.dir}" />
                                    <path refid="compile.classpath" />                  
                            </classpath>
                            <jvmarg value="-Xmx256M" />
                            <arg value="com.myCompany.web.Button" />
                    </java>
     </target>
    
    <target name="deploy" description="Build web project">
        <antcall target="clear_previous_war" />
        <antcall target="build_common" />
        <antcall target="build_dal" />
        <antcall target="copy_additional_files" />
        <antcall target="compile_web_classes" />
        <antcall target="compile_gwt_button" />
    </target>
    
    2 回复  |  直到 16 年前
        1
  •  4
  •   Ittai    16 年前

    compile-gwt 任务我没有给他通用模块的源路径(../common/src等),所以我添加了它,它就工作了。 类似:

    <classpath>
        <pathelement location="src"/>
        <pathelement location="../Common/src"/>
        <path refid="gwt.compile.classpath"/>
      </classpath>
    
        2
  •  0
  •   Drejc    16 年前

    做类似的事

    <condition property="gwtCompiler" value="gwt-dev-linux.jar">
        <os family="unix" />
    </condition>
    <condition property="gwtCompiler" value="gwt-dev-windows.jar">
        <not>
            <os family="unix" />
        </not>
    </condition>
    
    <echo>${gwtCompiler}</echo>
    
    <path id="gwt.compile.classpath">
            <pathelement path="${java.class.path}/" />
            <pathelement location="${gwt.sdk.location}/gwt-user.jar" />
    .. add here your dependencies
        <pathelement location="${gwt.sdk.location}/${gwtCompiler}" />
            <pathelement location="${gui.source}" />
    </path>
    
    <target name="compile-gwt" depends="compile-gui" description="GWT compile to JavaScript">
        <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
          <classpath>
            <pathelement location="src"/>
            <path refid="gwt.compile.classpath"/>
          </classpath>
          <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
          <jvmarg value="-Xmx256M"/>
          <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
          <arg value="${gwt.entrypoint.class}" />
        </java>
      </target>
    

    在哪里?

    • gwt.sdk.location-是gwt工具包jar所在的位置
    • $gwtcompiler-是使用的编译器(Linux/Windows)

    注释 :您需要删除 贾瓦克斯 从gwt-user.jar进行部署。 据我所知,这是一个开放的地方 issue

    推荐文章