“java -cp”之间的差异和“java -jar”? [英] Differences between "java -cp" and "java -jar"?

查看:638
本文介绍了“java -cp”之间的差异和“java -jar”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行Java应用程序与
java -cp CLASSPATH java -jar JAR_FILE_PATH ?对于运行Java应用程序,其中一个是否更喜欢另一个?我的意思是JVM中哪一种方法更昂贵(根据它们的机器资源使用情况)?

What is the difference between running a Java application with
java -cp CLASSPATH and java -jar JAR_FILE_PATH? Is one of them preferred to the other for running a Java application? I mean which one of these ways is more expensive for JVM (according to their machine resources usage)?

哪一种方法会导致JVM在尝试运行时产生更多线程应用程序?

Which one will cause JVM to spawn more threads while trying to run the application?

推荐答案

我更喜欢第一个版本启动java应用程序,因为它有较少的陷阱(欢迎来到类路径地狱 )。第二个需要一个可执行的jar文件,并且必须在jar的清单中定义该应用程序的类路径(所有其他类路径声明将被静默忽略...)。因此,对于第二个版本,您必须查看jar,读取清单并尝试查明类路径条目是否有效存储jar的位置......这是可以避免的。

I prefer the first version to start a java application just because it has less pitfalls ("welcome to classpath hell"). The second one requires an executable jar file and the classpath for that application has to be defined inside the jar's manifest (all other classpath declaration will be silently ignored...). So with the second version you'd have to look into the jar, read the manifest and try to find out if the classpath entries are valid from where the jar is stored... That's avoidable.

我不认为这两个版本都有任何性能优势或劣势。它只是告诉jvm哪个类用于主线程以及它可以在哪里找到库。

I don't expect any performance advantages or disadvantages for either version. It's just telling the jvm which class to use for the main thread and where it can find the libraries.

这篇关于“java -cp”之间的差异和“java -jar”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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