未找到包;爪哇 [英] Package not found; javac

查看:39
本文介绍了未找到包;爪哇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很烦人.

我有这样的目录结构

-lib
   --some jar files

-packageName
   --Main.java
   --SomeOtherPackage
      --SomeOtherJavaClass.java

Main.java 导入 SomeOtherPackage.并且两个 java 文件都使用 lib 中的 jar.

Main.java imports SomeOtherPackage. And both java files uses jars in the lib.

我所做的是在 CLASSPATH 中独立添加 jar 文件.然后运行为:javac 包名/Main.java

What I do is add the jar files independently in the CLASSPATH. And then run as: javac packageName/Main.java

但它给出了 Package not found SomeOtherPackage 的错误.它不应该自动实现依赖并构建 SomeOtherPackage 吗?上述情况的 javac 命令和类路径是什么?

but it gives the error that Package not found SomeOtherPackage . Shouldn't it automatically realize the dependency and build SomeOtherPackage as well? What would be the javac command and the classpath for the above case?

谢谢

推荐答案

通常的做法是将包根添加到类路径中.

The normal practice is to add the package root to the classpath.

如果您已经在包根目录中,请使用 -cp ..例如

When you're already in the package root, use -cp .. E.g.

cd /path/to/all/packages
javac -cp . packageName/Main.java

如果您还想包含 JAR 文件,请使用 ;(或在 *nix 中使用 :)作为类路径路径分隔符:

If you want to include JAR files as well, use the ; (or in *nix, the :) as classpath path separator:

javac -cp .;lib/file.jar packageName/Main.java

为了节省重复输入所有 shell 命令的时间,请使用 .bat(或在 *nix 中使用 .sh)文件.或者只是一个 IDE,如果您已经熟悉 java/javac 等.

To save the time in repeating all the typing of shell commands, use a .bat (or in *nix a .sh) file. Or just an IDE if you're already familiar with java/javac and so on.

这篇关于未找到包;爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆