2012-02-10 79 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>