为什么System.setProperty()不能在运行时更改类路径?

编程入门 行业动态 更新时间:2024-10-24 08:25:31
本文介绍了为什么System.setProperty()不能在运行时更改类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在参考问题以编程方式更改类路径。

I am refering to the question on changing the classpath programmatically.

我读过并发现 System 类下有一些函数作为getproperties,我们可以在其中检索属性然后也可以使用setProperties()设置它。

I read and found out that there is some function under System class as getproperties where we can retrieve the properties and then also can set it using setProperties().

但我得到的答案是它不会工作。我自己没试过,但是,我正在接听电话。

The answers however I got was that It Wont work. I have not tried this myself, however, i am taking the call.

为了澄清,为什么这些setProperty()和getProperty()方法如果不能在运行时改变它。或者这仅仅是针对classpath属性的?

Just to clarify, then why these setProperty() and getProperty() methods are there if they cannot alter it at run time. Or is this specific to the classpath property only ?

如果有人可以提供他们真正有帮助的场景,我将不胜感激?

I will appreciate if someone can present a scenario where they are really helpful?

推荐答案

您当然可以在任何时间设置所需的任何系统属性。问题是,它会产生什么影响吗?在类路径的情况下,答案是否定的。系统类加载器在启动序列的早期点初始化。它将类路径复制到自己的数据结构中,并且不再读取classpath属性。更改它不会影响系统中的任何内容。

You can certainly set any system properties you want at any point of time. The question is, will it have any effect? In the case of classpath, the answer is NO. The system class loader is initialized at a very early point in the startup sequence. It copies the classpath into its own data structures, and the classpath property is not read again. Changing it affect nothing in the system.

原因可能是双重的。性能较差的原因。您可能需要为快速查找资源而构建某种数据结构,并且每次重新解析类路径可能效率低下。更重要的原因是安全性。你不希望流氓类改​​变你下面的类路径并加载另一个类的受损版本。

The reason for this may be two-fold. The lesser reason is performance. You may need to have some sort of data structure built for quick lookup of resources, and re-parsing classpath every time may be inefficient. The more important reason is security. You don't want a rogue class change the classpath under you and load compromised version of another class.

更多推荐

为什么System.setProperty()不能在运行时更改类路径?

本文发布于:2023-10-31 05:01:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能在   路径   System   setProperty

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!