java.lang.System.setProperties()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(359)

本文整理了Java中java.lang.System.setProperties()方法的一些代码示例,展示了System.setProperties()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.setProperties()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:setProperties

System.setProperties介绍

[英]Sets all system properties. This does not take a copy; the passed-in object is used directly. Passing null causes the VM to reinitialize the properties to how they were when the VM was started.
[中]设置所有系统属性。这不需要拷贝;传入的对象直接使用。传递null将导致VM重新初始化属性,使其与VM启动时的状态一致。

代码示例

代码示例来源:origin: wildfly/wildfly

  1. public Void run() {
  2. System.setProperties(properties);
  3. return null;
  4. }
  5. }

代码示例来源:origin: apache/geode

  1. private static void removeJavaProperties(final Properties javaProps) {
  2. if (javaProps != null) {
  3. Properties props = System.getProperties();
  4. for (Iterator iter = javaProps.keySet().iterator(); iter.hasNext();) {
  5. props.remove(iter.next());
  6. }
  7. System.setProperties(props);
  8. }
  9. }

代码示例来源:origin: stackoverflow.com

  1. Properties p = new Properties(System.getProperties());
  2. p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
  3. p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level
  4. System.setProperties(p);

代码示例来源:origin: apache/geode

  1. @Override
  2. public void close() {
  3. // Clear the extra stuff from System properties
  4. Properties properties = System.getProperties();
  5. properties.remove(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT);
  6. properties.remove(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTHENTICATOR);
  7. Iterator iter = security.keySet().iterator();
  8. while (iter.hasNext()) {
  9. properties.remove(SECURITY_SYSTEM_PREFIX + iter.next());
  10. }
  11. System.setProperties(properties);
  12. }

代码示例来源:origin: spockframework/spock

  1. @Override
  2. public void intercept(IMethodInvocation invocation) throws Throwable {
  3. Properties original = new Properties();
  4. original.putAll(System.getProperties());
  5. try {
  6. invocation.proceed();
  7. } finally {
  8. System.setProperties(original);
  9. }
  10. }
  11. }

代码示例来源:origin: Netflix/conductor

  1. public static void teardown() {
  2. System.setProperties(null);
  3. }
  4. }

代码示例来源:origin: spotbugs/spotbugs

  1. public static void makeSystemPropertiesWriteOnce() {
  2. Properties properties = System.getProperties();
  3. if (properties instanceof WriteOnceProperties) {
  4. return;
  5. }
  6. System.setProperties(new WriteOnceProperties(properties));
  7. }

代码示例来源:origin: jphp-group/jphp

  1. @Signature
  2. public static void setProperties(Properties properties) {
  3. System.setProperties(properties);
  4. }

代码示例来源:origin: groovy/groovy-core

  1. public void tearDown() {
  2. System.setProperties(savedProperties);
  3. }

代码示例来源:origin: oracle/helidon

  1. @Override
  2. public void beforeTestExecution(ExtensionContext ec) throws Exception {
  3. getStore(ec).put(SYSPROPS_KEY, System.getProperties());
  4. Properties copy = new Properties();
  5. copy.putAll(System.getProperties());
  6. System.setProperties(copy);
  7. }

代码示例来源:origin: springside/springside4

  1. /**
  2. * Properties 本质上是一个HashTable,每次读写都会加锁,所以不支持频繁的System.getProperty(name)来检查系统内容变化 因此扩展了一个ListenableProperties,
  3. * 在其所关心的属性变化时进行通知.
  4. *
  5. * @see ListenableProperties
  6. */
  7. public static synchronized void registerSystemPropertiesListener(PropertiesListener listener) {
  8. Properties currentProperties = System.getProperties();
  9. // 将System的properties实现替换为ListenableProperties
  10. if (!(currentProperties instanceof ListenableProperties)) {
  11. ListenableProperties newProperties = new ListenableProperties(currentProperties);
  12. System.setProperties(newProperties);
  13. currentProperties = newProperties;
  14. }
  15. ((ListenableProperties) currentProperties).register(listener);
  16. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * Constructor.
  3. *
  4. * @param name Name.
  5. * @param val Value.
  6. */
  7. public SystemProperty(String name, String val) {
  8. this.name = name;
  9. Properties props = System.getProperties();
  10. originalValue = (String)props.put(name, val);
  11. System.setProperties(props);
  12. }

代码示例来源:origin: apache/ignite

  1. /** {@inheritDoc} */
  2. @Override public void close() {
  3. Properties props = System.getProperties();
  4. if (originalValue != null)
  5. props.put(name, originalValue);
  6. else
  7. props.remove(name);
  8. System.setProperties(props);
  9. }
  10. }

代码示例来源:origin: groovy/groovy-core

  1. public void setUp() {
  2. savedProperties = System.getProperties();
  3. System.setProperties(new Properties(savedProperties));
  4. }

代码示例来源:origin: org.apache.commons/commons-lang3

  1. /**
  2. * Tests that a lookup object for system properties can deal with a full
  3. * replacement of the system properties object. This test is related to
  4. * LANG-1055.
  5. */
  6. @Test
  7. public void testSystemPropertiesLookupReplacedProperties() {
  8. final Properties oldProperties = System.getProperties();
  9. final String osName = "os.name";
  10. final String newOsName = oldProperties.getProperty(osName) + "_changed";
  11. final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup();
  12. final Properties newProps = new Properties();
  13. newProps.setProperty(osName, newOsName);
  14. System.setProperties(newProps);
  15. try {
  16. assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName));
  17. } finally {
  18. System.setProperties(oldProperties);
  19. }
  20. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. @Override protected void after() {
  2. cleanUp();
  3. System.setProperties( originalProperties );
  4. Locale.setDefault( originalLocale );
  5. Locale.setDefault( Locale.Category.FORMAT, originalFormatLocale );
  6. LanguageChoice.getInstance().setDefaultLocale( originalLocale );
  7. TimeZone.setDefault( originalTimezone );
  8. FileUtils.deleteQuietly( tmpKettleHome.toFile() );
  9. }

代码示例来源:origin: gocd/gocd

  1. @After
  2. public void cleanUp() {
  3. System.setProperties(original);
  4. files.cleanUp();
  5. }

代码示例来源:origin: AsyncHttpClient/async-http-client

  1. @Test(enabled = false)
  2. public void testIgnoreProxyPropertiesByDefault() throws IOException, TimeoutException, InterruptedException {
  3. // FIXME not threadsafe!
  4. Properties originalProps = new Properties();
  5. originalProps.putAll(System.getProperties());
  6. System.setProperty(ProxyUtils.PROXY_HOST, "localhost");
  7. System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
  8. System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "localhost");
  9. AsyncHttpClientConfigHelper.reloadProperties();
  10. try (AsyncHttpClient client = asyncHttpClient()) {
  11. String target = "http://localhost:1234/";
  12. Future<Response> f = client.prepareGet(target).execute();
  13. try {
  14. f.get(3, TimeUnit.SECONDS);
  15. fail("should not be able to connect");
  16. } catch (ExecutionException e) {
  17. // ok, no proxy used
  18. }
  19. } finally {
  20. System.setProperties(originalProps);
  21. }
  22. }

代码示例来源:origin: AsyncHttpClient/async-http-client

  1. @Test(enabled = false)
  2. public void testWildcardNonProxyHosts() throws IOException, TimeoutException, InterruptedException {
  3. // FIXME not threadsafe!
  4. Properties originalProps = new Properties();
  5. originalProps.putAll(System.getProperties());
  6. System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
  7. System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
  8. System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "127.*");
  9. AsyncHttpClientConfigHelper.reloadProperties();
  10. try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) {
  11. String nonProxifiedTarget = "http://127.0.0.1:1234/";
  12. Future<Response> f = client.prepareGet(nonProxifiedTarget).execute();
  13. try {
  14. f.get(3, TimeUnit.SECONDS);
  15. fail("should not be able to connect");
  16. } catch (ExecutionException e) {
  17. // ok, no proxy used
  18. }
  19. } finally {
  20. System.setProperties(originalProps);
  21. }
  22. }

代码示例来源:origin: gocd/gocd

  1. @After
  2. public void after() {
  3. System.setProperties(original);
  4. new SystemEnvironment().reset(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE);
  5. }

相关文章