2010-02-10 103 views
5

我一直在使用GWT很长一段时间,现在只使用eclipse插件来编译我的项目。由于新的要求,我需要使用ant build(第一次)来构建gwt项目。首先我会说我有两个模块,它们有一个入口点,另外两个模块只包含java类(它们应该被翻译成js),并且它们位于我工作区中的不同项目中。使用蚂蚁编译gwt项目的问题

目前我有GWT项目需要反过来需要DAL项目的公共项目(当我要求我的意思是它在eclipse项目构建路径中定义时)。在我的GWT项目中,我在适当的位置有一个Common.gwt.xml和DAL.gwt.xml文件,它们将这些文件定义为模块,并且我的ModuleEntryPoint.gwt.xml继承了这两个模块(除了其他模块)。当我目前使用gwt eclipse插件编译一切正常。

但是,当我试图用ant构建这个模拟时,我的ModuleEntryPoint的编译失败,因为编译器说它无法找到属于DAL模块或Common模块的类的源。

蚂蚁构建代码是非常基本的,因为这是我的第一次尝试。
在此先感谢您获得的任何帮助。

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

回答

4

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

<classpath> 
    <pathelement location="src"/> 
    <pathelement location="../Common/src"/> 
    <path refid="gwt.compile.classpath"/> 
    </classpath> 
0

做类似的事情

<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删除的javax,进行部署。 据我知道这是STIL开放issue

+0

非常感谢,但我想我发现了这个问题。在'compile-gwt'任务中,我没有给他通用模块来源(../Common/src等)的路径,所以我已经添加了它,它的工作原理。谢谢。 – Ittai 2010-02-11 07:30:13