0

我正在尝试为我的 JBoss AS 7 项目制作一个 Ant 构建文件。构建文件应该将我的项目构建到 EAR 中。我收到以下错误,所以我认为类路径被某种方式忽略了(如果我错了,请纠正我)。

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)

所以现在我的构建文件看起来像这样: http: //pastebin.com/NZWmQEjN(在这里发布太长了)。如您所见,我放入了类路径部分。但现在我收到了这个错误:

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.

谁能看到我的构建文件有什么问题?

4

1 回答 1

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>被它寂寞的自我折腾。

您正在做的是创建一个可以在其他地方用作CLASSPATH的PATH 。你可能想要:

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

最后一个允许您在需要时添加多个类路径,有些人更喜欢它,因为它可以在需要时更容易地更改类路径。

于 2012-07-23T19:50:55.523 回答