本文整理汇总了Python中java.lang.ClassLoader.getSystemClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Python ClassLoader.getSystemClassLoader方法的具体用法?Python ClassLoader.getSystemClassLoader怎么用?Python ClassLoader.getSystemClassLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.ClassLoader
的用法示例。
在下文中一共展示了ClassLoader.getSystemClassLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_jython_jar
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def get_jython_jar():
from java.lang import ClassLoader # @UnresolvedImport
cl = ClassLoader.getSystemClassLoader()
paths = map(lambda url: url.getFile(), cl.getURLs())
for p in paths:
if 'jython.jar' in p:
return p
raise RuntimeError('Unable to find jython.jar')
示例2: __init__
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def __init__(self):
if ClassPath._instance:
self.__dict__.update(ClassPath._instance.__dict__)
else:
if 'CLASSPATH' in os.environ:
self._path = classpath.split(classpathsep)
else:
raise InstallationError("Cannot find CLASSPATH environmment variable")
self._stdloader = ClassLoader.getSystemClassLoader()
ClassPath._instance = self
示例3: addURL
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def addURL(self, u):
"""Purpose: Call this with u= URL for
the new Class/jar to be loaded"""
sysloader = javaClassLoader.getSystemClassLoader()
sysclass = URLClassLoader
method = sysclass.getDeclaredMethod("addURL", [javaURL])
a = method.setAccessible(1)
jar_a = jarray.array([u], javaObject)
b = method.invoke(sysloader, [u])
return u
示例4: __init__
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def __init__(self):
if ClassPath._instance:
self.__dict__.update(ClassPath._instance.__dict__)
else:
if 'CLASSPATH' in os.environ:
self._path = classpath.split(classpathsep)
else:
self._path = []
self._stdloader = ClassLoader.getSystemClassLoader()
ClassPath._instance = self
示例5: get_logging_config
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def get_logging_config():
"""Returns the absolute path to the logging config file
"""
# We need to find the path to the /pyrig
from java.lang import ClassLoader
cl = ClassLoader.getSystemClassLoader()
paths = map(lambda url: url.getFile(), cl.getURLs())
# Search all available paths for the one to /pyrig
path = next(x for x in paths if "pyrig" in x)
# Now we can return the absolute path to the logging file
return os.path.join(path, "logging.conf")
示例6: _jython_set_classpath
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def _jython_set_classpath(jars):
'''
import a jar at runtime (needed for JDBC [Class.forName])
adapted by Bastian Bowe from
http://stackoverflow.com/questions/3015059/jython-classpath-sys-path-and-jdbc-drivers
'''
from java.net import URL, URLClassLoader
from java.lang import ClassLoader
from java.io import File
m = URLClassLoader.getDeclaredMethod("addURL", [URL])
m.accessible = 1
urls = [File(i).toURL() for i in jars]
m.invoke(ClassLoader.getSystemClassLoader(), urls)
示例7: set_font
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def set_font(font_size):
'''
Loads font from resources' ttf file.
DejaVuSans doesn't work in Retina display screens properly, so check OS,
if OSX then use Monaco instead.
'''
# Take into account user preferred font size
if "mac" in System.getProperty("os.name").lower():
font = Font("Monaco", Font.PLAIN, font_size)
else:
path_to_ttf = 'resources/fonts/dejavu/ttf/DejaVuSans.ttf'
loader = ClassLoader.getSystemClassLoader()
stream = loader.getResourceAsStream(path_to_ttf)
font = Font.createFont(Font.TRUETYPE_FONT, stream)
font = font.deriveFont(Font.PLAIN, font_size)
return font
示例8: importJar
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def importJar(jarFile):
'''
import a jar at runtime (needed for JDBC [Class.forName])
adapted from http://forum.java.sun.com/thread.jspa?threadID=300557
Author: SG Langer Jan 2007 translated the above Java to Jython
Author: [email protected] simplified and updated for jython-2.5.3b3
>>> importJar('mysql-connector-java-5.1.29-bin.jar')
>>> import java.lang.Class
>>> java.lang.Class.forName('com.mysql.jdbc.Driver')
<type 'com.mysql.jdbc.Driver'>
'''
from java.net import URL, URLClassLoader
from java.lang import ClassLoader
from java.io import File
m = URLClassLoader.getDeclaredMethod("addURL", [URL])
m.accessible = 1
m.invoke(ClassLoader.getSystemClassLoader(), [File(jarFile).toURL()])
示例9: get_yaml_config
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def get_yaml_config(yaml_filename):
'''
Load contents of <yaml_filename> into dictionary.
Note file_handler's filename needs to be an absolute path and hence
manually changed from here.
'''
# Create helper object to load log config from jar resources
# Load config details from yaml file.
# Note getResource returns a java.net.URL object which is incompatible
# with Python's open method, so we need to work around it by copying the
# file to the home directory and open from there.
yaml_path = 'resources/config/{}'.format(yaml_filename)
loader = ClassLoader.getSystemClassLoader()
config_file_url = loader.getResource(yaml_path)
# In Unix getResource returns the path with prefix "file:" but in
# Windows prefix is "jar:file:"
path_to_jar = str(config_file_url).split('file:')[1]
path_to_jar = path_to_jar.split('!')[0]
path_to_config = get_log_path(yaml_filename)
# Check if log config file exists already.
# If it doesn't, paste it from JAR's resources to there.
# If it does, check is up to date with latest version
if not os.path.isfile(path_to_config):
copy_yaml_to_home(path_to_jar, yaml_path, path_to_config)
else:
# We are running from the JAR file, not the local console
update_yaml_config(path_to_jar, yaml_path, path_to_config)
# Load local YAML file and perform required patches on the settings in
# memory if the settings version is different between the jar and the local
# file. Ensures that memory and file settings always match.
(jar_config, local_config,
jar_version, local_version) = get_config_versions(path_to_jar, yaml_path,
path_to_config)
if yaml_filename == 'settings.yaml':
if different_versions(jar_version, local_version):
return patch_config(local_config)
return local_config
示例10: read_from_jar
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def read_from_jar(relative_path):
'''
reads a file from within a jar. returns the file content
'''
from java.lang import ClassLoader
from java.io import InputStreamReader, BufferedReader
loader = ClassLoader.getSystemClassLoader()
stream = loader.getResourceAsStream(relative_path)
reader = BufferedReader(InputStreamReader(stream))
line = reader.readLine()
buf = ''
while line is not None:
buf += line
line = reader.readLine()
reader.close()
stream.close()
return buf
示例11: addFile
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def addFile(jarFile):
'''
http://stackoverflow.com/questions/3015059/jython-classpath-sys-path-and-jdbc-drivers
import a jar at runtime (needed for JDBC [Class.forName])
adapted from http://forum.java.sun.com/thread.jspa?threadID=300557
Author: SG Langer Jan 2007 translated the above Java to Jython
Author: [email protected] simplified and updated for jython-2.5.3b3
>>> importJar('jars/jtds-1.2.5.jar')
>>> import java.lang.Class
>>> java.lang.Class.forName('net.sourceforge.jtds.jdbc.Driver')
<type 'net.sourceforge.jtds.jdbc.Driver'>
'''
from java.net import URL, URLClassLoader
from java.lang import ClassLoader
from java.io import File
m = URLClassLoader.getDeclaredMethod("addURL", [URL])
m.accessible = 1
m.invoke(ClassLoader.getSystemClassLoader(), [File(jarFile).toURL()])
return
示例12: load
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def load(self, img_file, namehint=None):
"""
Load image from file as a java.awt.image.BufferedImage.
Return the bufferedimage as a Surface.
"""
try:
try:
f = env.japplet.class.getResource(img_file.replace('\\','/')) #java uses /, not os.path Windows \
if not f:
raise
except:
cload = ClassLoader.getSystemClassLoader()
f = cload.getResourceAsStream(img_file.replace('\\','/'))
print "fe"
except:
f = File(img_file)
bimage = ImageIO.read(f)
surf = Surface(bimage)
return surf
示例13: execute
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def execute(self):
self.customize(self.options)
connection = None
try:
connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
connection.setWorkingDirectory(connection.getFile(self.remotePath))
# upload the script and pass it to cscript.exe
targetFile = connection.getTempFile('parameters', '.txt')
OverthereUtils.write(String(self.script).getBytes(), targetFile)
targetFile.setExecutable(True)
exeFile = connection.getTempFile('HpToolsLauncher', '.exe')
sysloader = ClassLoader.getSystemClassLoader()
OverthereUtils.write(sysloader.getResourceAsStream("HpTools/HpToolsLauncher.exe"), exeFile)
exeFile.setExecutable(True)
# run cscript in batch mode
scriptCommand = CmdLine.build(exeFile.getPath(), '-paramfile', targetFile.getPath())
return connection.execute(self.stdout, self.stderr, scriptCommand)
except Exception, e:
stacktrace = StringWriter()
writer = PrintWriter(stacktrace, True)
e.printStackTrace(writer)
self.stderr.handleLine(stacktrace.toString())
return 1
示例14: findImageResource
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def findImageResource(self, name):
#Create helper object to load icon images in jar
loader = ClassLoader.getSystemClassLoader()
#Load image
return loader.getResource("resources/images/" + name + ".png")
示例15: __init__
# 需要导入模块: from java.lang import ClassLoader [as 别名]
# 或者: from java.lang.ClassLoader import getSystemClassLoader [as 别名]
def __init__(self):
self.system_class_loader = ClassLoader.getSystemClassLoader()
self.url_class_loader = URLClassLoader