且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有类似VirtualEnv for Java的东西?

更新时间:2023-11-28 23:43:34

据我了解,virtualenv使您能够拥有单独的库安装路径,有效地分隔虚拟" Python安装.

From what I understand, virtualenv enables you to have separate library installation paths, effectively separate "virtual" Python installations.

Java没有已在系统范围内安装"库的概念(*):它始终在类路径中搜索要加载的库.由于可以为每个应用程序定义类路径,因此每个应用程序都可以选择要加载的库和版本.

Java doesn't have the concept of a "system-wide installed" library(*): It always searches the classpath for the libraries to be loaded. Since the classpath can be (and needs to be!) defined for each application, each application can pick-and-choose which libraries and which versions it wants to load.

如果您更深入地了解一个单一的应用程序,而该应用程序某种程度上需要同时使用同一库的两个不同版本,那么您甚至可以使用一些类路径技巧来做到这一点.它可能会变得复杂,但是绝对有可能(OSGi是支持此功能的一个示例,即使具有两个独立Web应用程序的Tomcat都可以做到这一点.)

If you go down one level deeper and have a single application that somehow needs two different versions of the same library at the same time, then you can do even that with some classpath trickery. It can get complicated, but it's definitely possible (OSGi is one example where this is supported, even Tomcat with two separate webapplications does this).

我在virtualenv描述中看到了一些安全性参考:Java内置了相当全面的安全性系统.在服务器应用程序中,通常会关闭它,因为这样做更容易配置,但是您可以轻松地配置允许使用Java应用程序.

I've seens some references to security in the virtualenv description: Java has a pretty thorough security system built in. In server applications it's often turned off because it's just easier to configure this way, but you can easily configure what exactly a Java application is allowed to do.

(*)几乎有扩展或扩展库,但是它们使用不多,甚至可以轻松地从任意目录中加载它们.

(*) Almost, there are extensions or extension libraries, but they aren't used a lot and even those can easily be loaded from arbitrary directories.