java编译和运行时库
我是java新手,我花了几个小时来解决这个问题。我将非常感谢任何能够帮助我的人。
问题就在这里。
- 我的项目,比如说 ProjectA,需要一个 一堆要编译的库,但我 我认为我不需要一个名为 库B.jar。所以这个项目 无需 LibraryB 即可正确编译 在类路径中。
- 运行时,程序退出 没有任何错误消息。我没有 知道原因直到我把 当我运行时,LibraryB.jar 在类路径中 我的项目
有人能告诉我为什么会发生这种情况吗?据我所知,在java中,如果我引用LibraryB.jar,那么在编译和链接时将需要它。也许我错了。
I am new in java, I have spent hours for this problem. I will be really thankful for anyone who can help me.
Here is the problem.
- My project, say ProjectA, need a
bunch of libraries to compile, but I
don't think I need a library called
LibraryB.jar. So the project
compiled correctly without LibraryB
in the class path. - At runtime, the program exited
without any error message. I didn't
know the reason until I put
LibraryB.jar in classpath when I run
my project
Could anyone tell me why this is happening? As I know, in java, If I referenced LibraryB.jar, it would be needed at compile and link time. Maybe I am wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于缺乏具体的例子,我只能给你一个高层次的概述:
如果你的项目使用依赖于 LibraryB 的 LibraryA 但实际上并没有在其接口中公开任何 LibraryB 的类(即它只在内部使用它),那么你可以轻松地陷入这样的情况:您只需要 LibraryA 进行编译,但需要 LibraryB 来实际运行代码。
如果您的应用程序退出时没有出现错误消息,那么通常是您自己的错误。特别是对于刚接触 Java 的人来说,造成这种情况的一个常见原因是空的
catch
块(不要这样做!):Lacking concrete examples, I can only give you a high-level overview:
If your project uses LibraryA that depends on LibraryB but does not actually expose any of LibraryB's classes in its interfaces (i.e. it only uses it internally), then you can easily come into a situation where you only need LibraryA to compile, but need LibraryB to actually run your code.
If your application exits without an error message, then it's your own fault, more often than not. Especially for people new to Java, a common cause for this is empty
catch
-blocks (don't do this!):