我已经创建了一个包,并使用ant将其编译成一个jar文件。
文件结构是这样的
project folder
x_package
compiled package_x.jar
com
name
package_x
Package files
demos
src
files I'm trying to compile
我正在尝试编译demo/src下的文件,这些文件依赖于已编译的package_x.jar
我通过将package_x.jar作为javac任务
的参数添加到类路径来实现这一点<<p> Javac任务/strong> <javac destdir = "${build.dir}" source = "${ant.java.version}" target = "${ant.java.version}"
debug = "true" deprecation = "false" optimize = "false" failonerror = "true" >
<src path = "${source.dir}" />
<classpath refid = "master-classpath"/>
</javac>
master-classpath
<path id = "master-classpath" >
<fileset dir = "${classpath.dir}" >
<include name = "*.jar" />
</fileset>
<pathelement path = "${classpath.dir}" />
</path>
每当我运行ant文件时,就会出现2个错误
error: package package_x does not exist
和在第一次引用包
中定义的类时error: Cannot access class_name
bad class file C:/(path)/package_x.jar (class_name)
class file contains wrong class: package_x.class_name
please remove or make sure it appears in the correct subdirectory of the classpath
在package_x包中,每个文件都以
开头package package_x;
/*code*/
和demos目录下的文件有
import package_x.*;
/*code*/
欢迎指教
我不确定这是否是唯一的问题,但在包声明和导入中,您必须编写完整的包路径,如com.name.package_x