Ant -verbose 失败并显示“包不存在”尽管 jar 位于类路径上

发布于 2024-09-28 05:35:24 字数 2122 浏览 7 评论 0原文

我有以下代码

package myPackage;

import org.neo4j.graphdb;
import org.neo4j.kernel.EmbeddedGraphDatabase;

public class dbServlet extends HttpServlet {

public void init() throws ServletException {
    // Start up the database here                                                      
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("var/base");

}

public void destroy() {
    graphDb.shutdown();

}

和 build.xml 文件:

<project name="dbServlet" basedir="." default="compile">

  <property name="src.dir" value="src"/>
  <property name="lib.dir" value="lib"/>
  <property name="build.dir"  value="build"/>
  <property name="classes.dir"  value="${build.dir}/classes"/>
  <property name="jar.dir"  value="${build.dir}/jar"/>

  <path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
  </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
    </target>

</project>

所有 neo4j jar 都位于 build.xml 文件所在的 lib 目录中。源代码位于 src/myPackage/dbServlet.java。当我运行 ant -v 时,类路径包含具有 neo4j 类的 jar,但 javac 说这些包不存在。有人知道为什么会这样吗?

下面是错误的片段(我现在关心的是第一个错误,我知道 servlet api 尚未在路径上):

[javac] /home/shaun/projects/helloAnt/src/myPackage/dbServlet.java:3: package org.neo4j does not exist
[javac] import org.neo4j.graphdb;
[javac]                 ^
[javac] /home/shaun/projects/helloAnt/src/myPackage/dbServlet.java:6: cannot find symbol
[javac] symbol: class HttpServlet
[javac] public class dbServlet extends HttpServlet {
[javac]                                ^
[javac] /home/shaun/projects/helloAnt/src/myPackage/dbServlet.java:8: cannot find symbol
[javac] symbol  : class ServletException
[javac] location: class myPackage.dbServlet
[javac]     public void init() throws ServletException {
[javac]                               ^

I have the following code

package myPackage;

import org.neo4j.graphdb;
import org.neo4j.kernel.EmbeddedGraphDatabase;

public class dbServlet extends HttpServlet {

public void init() throws ServletException {
    // Start up the database here                                                      
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("var/base");

}

public void destroy() {
    graphDb.shutdown();

}

and build.xml file:

<project name="dbServlet" basedir="." default="compile">

  <property name="src.dir" value="src"/>
  <property name="lib.dir" value="lib"/>
  <property name="build.dir"  value="build"/>
  <property name="classes.dir"  value="${build.dir}/classes"/>
  <property name="jar.dir"  value="${build.dir}/jar"/>

  <path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
  </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
    </target>

</project>

All of the neo4j jars are located in a lib directory where the build.xml file is. The source is located at src/myPackage/dbServlet.java. When I run ant -v, the classpath includes the jars that have the neo4j classes, but javac is saying the packages don't exist. Anyone know why this could be?

Heres a snippet of the errors (I'm concerned with the first one for now, I know that the servlet api's aren't on the path yet):

[javac] /home/shaun/projects/helloAnt/src/myPackage/dbServlet.java:3: package org.neo4j does not exist
[javac] import org.neo4j.graphdb;
[javac]                 ^
[javac] /home/shaun/projects/helloAnt/src/myPackage/dbServlet.java:6: cannot find symbol
[javac] symbol: class HttpServlet
[javac] public class dbServlet extends HttpServlet {
[javac]                                ^
[javac] /home/shaun/projects/helloAnt/src/myPackage/dbServlet.java:8: cannot find symbol
[javac] symbol  : class ServletException
[javac] location: class myPackage.dbServlet
[javac]     public void init() throws ServletException {
[javac]                               ^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法回应 2024-10-05 05:35:24

在我看来,您的导入不太正确 - 您想导入 org.neo4j.graphdb 包中的所有类吗?

import org.neo4j.graphdb.*;

否则你应该给出一个特定的类名。 javac 错误消息表明正在寻找包 org.neo4j - graphdb 被视为类名。

It looks to me like your import is not quite right - do you want to import all the classes in the org.neo4j.graphdb package?

import org.neo4j.graphdb.*;

Else you should give a specific class name. The javac error message indicates that a package org.neo4j is being sought - graphdb is being treated as a class name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文