Jython通过WLST监控WebLogic时,导致Jython自带的py模块不能使用

startJySpy.cmd

@ECHO OFF
SETLOCAL

set WL_HOME=C:\Oracle\Middleware\wlserver_10.3
call "%WL_HOME%\server\bin\setWLSEnv.cmd"

java -Dweblogic.security.SSL.ignoreHostnameVerification=true ^
     -Dweblogic.security.TrustKeyStore=DemoTrust ^
     weblogic.WLST ^
     JySpy.py

ENDLOCAL
PAUSE

JySpy.py

#!/usr/bin/env jython
# -*- coding: utf-8 -*-

import os
import wl
import sys
sys.path.append('C:\\jython2.7.0\\Lib')
sys.path.append('C:\\jython2.7.0\\Lib\\site-packages')
import signal
import hashlib
#import json
#import uuid
#import xml.etree.ElementTree as ET

Output


CLASSPATH="C:\Oracle\MIDDLE~1\patch_wls1036\profiles\default\sys_manifest_classp ath\weblogic_patch.jar;C:\Oracle\MIDDLE~1\patch_ocp371\profiles\default\sys_mani fest_classpath\weblogic_patch.jar;C:\Java\JDK17~1.0_7\lib\tools.jar;C:\Oracle\MI DDLE~1\WLSERV~1.3\server\lib\weblogic_sp.jar;C:\Oracle\MIDDLE~1\WLSERV~1.3\serve r\lib\weblogic.jar;C:\Oracle\MIDDLE~1\modules\features\weblogic.server.modules_1 0.3.6.0.jar;C:\Oracle\MIDDLE~1\WLSERV~1.3\server\lib\webservices.jar;C:\Oracle\M IDDLE~1\modules\ORGAPA~1.1/lib/ant-all.jar;C:\Oracle\MIDDLE~1\modules\NETSFA~1.0 _1/lib/ant-contrib.jar;.;C:\Java\jdk1.7.0_76\lib\dt.jar;C:\Java\jdk1.7.0_76\lib\ tools.jar" PATH="C:\Oracle\MIDDLE~1\patch_wls1036\profiles\default\native;C:\Oracle\MIDDLE~ 1\patch_ocp371\profiles\default\native;C:\Oracle\MIDDLE~1\WLSERV~1.3\server\nati ve\win\32;C:\Oracle\MIDDLE~1\WLSERV~1.3\server\bin;C:\Oracle\MIDDLE~1\modules\OR GAPA~1.1\bin;C:\Java\JDK17~1.0_7\jre\bin;C:\Java\JDK17~1.0_7\bin;C:\jython2.7.0\ bin;C:\Python27\;C:\Python27\Scripts;C:\Java\jdk1.7.0_76\bin;C:\Java\jdk1.7.0_76 \jre\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Oracle\MIDDL E~1\WLSERV~1.3\server\native\win\32\oci920_8" Your environment has been set. Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Problem invoking WLST - Traceback (innermost last): File "C:\WORK\JySpy.py", line 10, in ? File "C:\jython2.7.0\Lib\hashlib.py", line 141, in ? File "C:\jython2.7.0\Lib\logging\__init__.py", line 809 finally: ^ SyntaxError: invalid syntax 请按任意键继续. . .

import json

Problem invoking WLST - Traceback (innermost last):
  File "C:\WORK\JySpy.py", line 11, in ?
  File "C:\jython2.7.0\Lib\json\__init__.py", line 108
        from .decoder import JSONDecoder
             ^
SyntaxError: invalid syntax

import uuid

Problem invoking WLST - Traceback (innermost last):
  File "C:\WORK\JySpy.py", line 12, in ?
  File "C:\jython2.7.0\Lib\uuid.py", line 305
                    with os.popen(cmd) as pipe:
                         ^
SyntaxError: invalid syntax

import xml.etree.ElementTree as ET

Problem invoking WLST - Traceback (innermost last):
  File "C:\WORK\JySpy.py", line 13, in ?
ImportError: no module named etree

如果仅是Jython调用其自带模块时,运行是OK的,代码如下:

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\zta>cd\

C:\>jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) Client VM (Oracle Corporation)] on java1.7.0_76
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import sys
>>> import hashlib
>>> import json
>>> import uuid
>>> import signal
>>> import xml.etree.ElementTree as ET
>>>
>>> sys.path
['', 'C:\\jython2.7.0\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\jython2.7
.0\\Lib\\site-packages']
>>> exit()

C:\>

请问,引入WLST模块后,Jython怎样才能正确使用其自带的py模块?

阅读 5.5k
1 个回答
新手上路,请多包涵

是不是包路径的问题,看看python目录是否有想应的py文件

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏