2012-07-23 118 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