2012-02-10 80 views
1

我想在命令行上通过Ant编译一个可编译Eclipse的GWT项目(通过Ant)。为Ant build.xml创建GWT编译规则

Eclipse提供的功能可以导出build.xml;这对编译类很有效,但由于GWT的特殊功能都是通过插件提供的,因此不包括这些规则。

Google提供a tool用于为新项目创建build.xml文件。我已将由此生成的规则合并到Eclipse导出的文件中。

编译(由Eclipse提供的部分)是成功的。

以下是编译的东西到JavaScript的任务:

<target name="gwtc" depends="build" description="GWT compile to JavaScript (production mode)"> 
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler"> 
     <classpath> 
     <pathelement location="war/WEB-INF/classes"/> 
     <pathelement location="src"/> 
     <path refid="project.class.path"/> 
     <pathelement location="/Applications/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0/validation-api-1.0.0.GA.jar" /> 
     <pathelement location="/Applications/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0/validation-api-1.0.0.GA-sources.jar" /> 
     </classpath> 
     <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError --> 
     <jvmarg value="-Xmx256M"/> 
     <!--<arg line="-style PRETTY"/>--> 
     <arg line="-war"/> 
     <arg value="war"/> 
     <!-- Additional arguments like -style PRETTY or -logLevel DEBUG --> 
     <arg line="${gwt.args}"/> 
     <arg value="edu.calpoly.csc.scheduler"/> 
    </java> 
    </target> 

.gwt.xml文件看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>             
<module rename-to='gwtview'>               
    <!-- Inherit the core Web Toolkit stuff.      -->     
    <inherits name='com.google.gwt.user.User'/>           

    <!-- Inherit the default GWT style sheet. You can change  --> 
    <!-- the theme of your GWT application by uncommenting   -->     
    <!-- any one of the following lines.       -->     
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>        
    <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->    
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->     
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>  -->     

    <!-- Other module inherits          -->     

    <!-- Specify the app entry point class.       -->     
    <entry-point class='edu.calpoly.csc.scheduler.view.client.GWTView'/>                           
    <!-- Specify the paths for translatable code     -->     
    <source path='client'/>                
    <source path='shared'/> 
    <source path='view'/>                 

</module> 

当试图运行的任务,我得到这个错误:

gwtc: 
    [java] Compiling module edu.calpoly.csc.scheduler 
    [java] Finding entry point classes 
    [java]  [ERROR] Unable to find type 'edu.calpoly.csc.scheduler.view.client.GWTView' 
    [java]   [ERROR] Hint: Previous compiler errors may have made this type unavailable 
    [java]   [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly 

对我来说这似乎很奇怪,因为这个班上有很多:

[$]> ls war/WEB-INF/classes/edu/calpoly/csc/scheduler/view/client 
GWTView$1.class   GWTView$1MyHandler.class GreetingService.class 
GWTView$1MyHandler$1.class GWTView.class    GreetingServiceAsync.class 

Halp?

回答

2

你确定你的类路径上有你的GWT应用程序的源代码吗? GWT正在将java源文件编译为js,而不是* .class文件。

+0

是的。 'ls src/edu/calpoly/csc/scheduler/view/client'显示'GWTView.java'。 – 2012-02-13 20:04:34

+0

@XiongChiamiov好吧,这意味着gwt.xml不包含'view'包。文件edu/calpoly/csc/scheduler.gwt.xml是否包含''标签? – jusio 2012-02-13 21:08:50

+0

它没有;我添加了它,但仍然得到相同的错误。我已经更新了问题以包含完整的'scheduler.gwt.xml'文件内容。 – 2012-02-15 20:13:20

1

请确保您已将该库/ jar以及您传递给GWT编译器的类路径中需要的任何其他源所需的源文件传递给GWT编译器,因为它需要能够在GWT库中查找Java源代码以便能够编译它们,与Javac编译器不同,它只能使用提供的.class文件针对库进行编译。

这是我的ant gwtc编译宏。 (除去导致<避免格式化问题...)

macrodef name="gwtCompileApplication" > 
    <attribute name="app" /> 
    <attribute name="extraArgs" default="" /> 
    <attribute name="gwtcExtras" default="" /> 
    <sequential> 
     <java classpathref="gwtCompile.classpath" classname="com.google.gwt.dev.Compiler" fork="true" failonerror="true"> 
      <jvmarg value="-Xmx512M" /> 

      <arg value="-strict" /> 

      <!-- Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors. 
      <arg value="-logLevel" /> 
      <arg value="DEBUG" /> 
    --> 

      <!-- request detailed, non-obfuscated JS output 
      <arg value="-style" /> 
      <arg value="DETAILED" /> 
    --> 

      <arg value="-localWorkers" /> 
      <arg value="4" /> 

      <arg value="-war" /> 
      <arg value="${war.dir}" /> 

      <arg value="-deploy" /> 
      <arg value="deploy" /> 

      <!-- These two lines have been removed as otherwise it won't work on Mac OS X 
        <arg value="@{extraArgs}" /> 
        <arg value="@{gwtcExtras}" /> 
      --> 

      <!-- This can be used to see more details about warnings, but they will be converted to errors and build will fail 
      <arg value="-strict" /> 
      --> 

      <arg value="-logLevel" /> 
      <arg value="INFO" /> 

      <arg value="@{app}" /> 
     </java> 
    </sequential> 
</macrodef> 

这可以从这样的任何目标被调用: 甲目标编译我的一个特定模块称为“管理”,其中文件Admin.gwt.xml文件是内部.ta.Admin。我有一个调试和生产版本类型和.gwt.xml为每一个不同的,以加快编译为调试(较少的用户代理和语言=更少置换)

target name="gwtcAdmin" depends="compile, buildtype" description="GWT Compile Admin" > 
    <gwtCompileApplication app="com.bcntouch.ta.Admin.${build_type}_Admin" extraArgs="${gwtcArgs}" gwtcExtras="${gwtcExtras}"/> 
</target> 

但关键部分,如果我使用GWT编译类路径。这是我设置路径的目标:

target name="gwtPath"> 
    <path id="gwt.classpath"> 
     <pathelement location="${gwt.sdk.dir}/gwt-user.jar" /> 
     <pathelement location="${gwt.sdk.dir}/gwt-servlet.jar" /> 
    </path> 

    <!-- For GWT compile we need a path with source AND the GWT Compiler classes --> 
    <path id="gwtCompile.classpath"> 
     <path refid="source.classpath" /> 
     <!-- This is put after source, so GWT Compiler it doesn't pick up out of date versions of old css and uibinder 
      files in classes generated by Eclipse/GWT Plugin --> 
     <path refid="classpath" /> 
     <path refid="tool.classpath" /> 
    </path>  
</target>