-
Notifications
You must be signed in to change notification settings - Fork 331
/
jvm.py
53 lines (40 loc) · 1.54 KB
/
jvm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/python
# -*- coding: utf-8 -*-
import logging
import os
import sys
try:
import jpype
except ImportError:
pass
from . import utils
def init_jvm(jvmpath=None):
"""Initializes the Java virtual machine (JVM).
:param jvmpath: The path of the JVM. If left empty, inferred by :py:func:`jpype.getDefaultJVMPath`.
"""
if jpype.isJVMStarted():
logging.warning('JVM is already running. Do not init twice!')
return
folder_suffix = [
'{0}', '{0}{1}bin',
'{0}{1}jhannanum-0.8.4.jar',
'{0}{1}kkma-2.0.jar',
'{0}{1}komoran-2.4-e.jar',
'{0}{1}shineware-common-2.0.jar', '{0}{1}shineware-ds-1.0.jar',
'{0}{1}snakeyaml-1.12.jar', '{0}{1}scala-library-2.11.4.jar', '{0}{1}twitter-korean-text-2.4.3.jar', '{0}{1}twitter-text-1.10.1.jar',
'{0}{1}*']
javadir = '%s%sjava' % (utils.installpath, os.sep)
args = [javadir, os.sep]
classpath = os.pathsep.join(f.format(*args) for f in folder_suffix)
jvmpath = jvmpath or jpype.getDefaultJVMPath()
# NOTE: Temporary patch for Issue #76. Erase when possible.
if sys.platform == 'darwin'\
and jvmpath.find('1.8.0') > 0\
and jvmpath.endswith('libjvm.dylib'):
jvmpath = '%s/lib/jli/libjli.dylib' % jvmpath.split('/lib/')[0]
if jvmpath:
jpype.startJVM(jvmpath, '-Djava.class.path=%s' % classpath,
'-Dfile.encoding=UTF8',
'-ea', '-Xmx1024m')
else:
raise ValueError("Please specify the JVM path.")