找不到包裹; javac的 [英] Package not found; javac

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

问题描述

这很烦人。

我有这样的目录结构

-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 packageName / Main.java

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

但是它给出了找不到包的错误 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 a .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.

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

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