2012-07-23 90 views
0

我試圖讓一個Ant構建文件爲我的JBoss AS 7項目。構建文件應該將我的項目構建到EAR中。我得到以下錯誤,所以我認爲類路徑被忽略了(請糾正我,如果我錯了)。類路徑在Ant構建文件

C:\workspace\LearningAS7\GrahamsProj\build-handmade.xml:21: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds 
Compiling 4 source files to C:\workspace\LearningAS7\GrahamsProj\build 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:4: package javax.persistence does not exist 
import javax.persistence.*; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:10: cannot find symbol 
symbol: class Entity 
@Entity 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:11: cannot find symbol 
symbol: class Table 
@Table(name="schemas") 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:12: cannot find symbol 
symbol: class SequenceGenerator 
@SequenceGenerator(name="seq_schemas", sequenceName = "") 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\delegate\GrahamsProjBean.java:7: package javax.ejb does not exist 
import javax.ejb.Stateless; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\delegate\GrahamsProjBean.java:8: package javax.persistence does not exist 
import javax.persistence.EntityManager; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\delegate\GrahamsProjBean.java:9: package javax.persistence does not exist 
import javax.persistence.PersistenceContext; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\interfaces\GrahamsProjBeanLocal.java:3: package javax.ejb does not exist 
import javax.ejb.Local; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\interfaces\GrahamsProjBeanLocal.java:8: cannot find symbol 
symbol: class Local 
@Local 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\interfaces\GrahamsProjBeanRemote.java:3: package javax.ejb does not exist 
import javax.ejb.Remote; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\interfaces\GrahamsProjBeanRemote.java:8: cannot find symbol 
symbol: class Remote 
@Remote 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\delegate\GrahamsProjBean.java:15: cannot find symbol 
symbol: class Stateless 
@Stateless 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\delegate\GrahamsProjBean.java:18: cannot find symbol 
symbol : class EntityManager 
location: class grahamsproj.session.delegate.GrahamsProjBean 
EntityManager em; 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:52: cannot find symbol 
symbol : class Id 
location: class grahamsproj.entity.Schemas 
@Id 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:53: cannot find symbol 
symbol : class Column 
location: class grahamsproj.entity.Schemas 
@Column(name = "ID") 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\entity\Schemas.java:54: cannot find symbol 
symbol : class GeneratedValue 
location: class grahamsproj.entity.Schemas 
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_schemas") 

C:\workspace\LearningAS7\GrahamsProj\src\grahamsproj\session\delegate\GrahamsProjBean.java:17: cannot find symbol 
symbol : class PersistenceContext 
location: class grahamsproj.session.delegate.GrahamsProjBean 
@PersistenceContext 

17 errors 
C:\workspace\LearningAS7\GrahamsProj\build-handmade.xml:21: Compile failed; see the compiler error output for details. 
BUILD FAILED (total time: 0 seconds) 

所以現在我的build文件看起來像這樣:http://pastebin.com/NZWmQEjN(太長,張貼在這裏的)。正如你所看到的,我放入了一個classpath部分。但現在我得到這個錯誤:

C:\workspace\LearningAS7\GrahamsProj\build-handmade.xml:11: Problem: failed to create task or type classpath 
Cause: The name is undefined. 
Action: Check the spelling. 
Action: Check that any custom tasks/types have been declared. 
Action: Check that any <presetdef>/<macrodef> declarations have taken place. 

任何人都可以看到我的構建文件有什麼問題嗎?

+0

這主要取決於什麼是由在build-impl.xml中可能定義的變量第三party_jars引用... – poussma 2012-07-23 18:49:10

回答

4

您有:

<classpath> 
    <pathelement path="${classpath}"/> 
     <fileset dir="lib"> 
      <include name="**/*.jar"/> 
     </fileset> 
     <pathelement location="classes"/> 
     <dirset dir="${build.dir}"> 
      <include name="apps/**/classes"/> 
      <exclude name="apps/**/*Test*"/> 
     </dirset> 
     <filelist refid="third-party_jars"/> 
    </classpath> 

但是,你不能簡單地折騰<classpath>了它的寂寞的自我。

你在做什麼是創建一個PATH可以用作CLASSPATH別處。你可能想:

<path id="class.path"> 
    <pathelement path="${classpath}"/> 
     <fileset dir="lib"> 
      <include name="**/*.jar"/> 
     </fileset> 
     <pathelement location="classes"/> 
     <dirset dir="${build.dir}"> 
      <include name="apps/**/classes"/> 
      <exclude name="apps/**/*Test*"/> 
     </dirset> 
     <filelist refid="third-party_jars"/> 
</path> 

現在,您可以使用PATH當你需要指定類路徑:

<javac srcdir="${src}" 
     destdir="${build}" 
     classpathref="class.path"/> 

或者......

<javac srcdir="${src} 
     destdir="${build}"> 
     <classpath> 
      <path refid="class.path"/> 
     </classpath> 
    </javac> 

最後如果需要,可以添加多個類路徑,而有些人更喜歡它,因爲它可以在r時更改類路徑equired。

+0

我的問題是我不知道每個這些命令的執行。我查閱了ANT命令參考,並且「路徑」不在那裏。另外一些其他人不在那裏。你知道解釋他們的參考嗎? – Graham 2012-07-24 19:31:28

+0

@Graham你可能在[任務參考]只想找(http://ant.apache.org/manual/tasklist.html)。路徑位於[概念和類型](http://ant.apache.org/manual/conceptstypeslist.html)根據[路徑狀結構](http://ant.apache.org/manual/using.html#路徑)。您也應該檢查出的[參考](http://ant.apache.org/manual/using.html#references)部分,它告訴你如何可以定義諸如路徑,文件集等東西,後來又引用它上。注意你用'id'參數來定義,但是用'refid'參數來引用它。 – 2012-07-24 19:44:44

+0

謝謝,這些幫助很大。另外,我做了你提出的改變,但我仍然得到相同的錯誤。還有其他一些事情正在發生。我從教程中複製並粘貼了該類的XML路徑,因此它不是特定於我的項目。另外,'**'和'*'在名稱屬性中的含義是什麼? – Graham 2012-07-24 20:51:51