wsadmin + jython delete folder

╄→尐↘猪︶ㄣ 提交于 2019-12-11 10:30:14

问题


I want to do post-deploy script using standalone wsadmin. It should delete all caches on profile (/profile/temp /profile/myCacheFolder). My question is, is it possible to do this with wsadmin? If so how? Can I somehow use AdminConfig.deleteDocument or something like this?

thank you


回答1:


With AntAgent MBean you can upload ant script and then invoke it on remote node:

http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.javadoc.doc/web/mbeanDocs/AntAgent.html

from java.lang import String
import jarray

fileContent = '<project name="cleanup" default="cleanup"><target name="cleanup"><delete dir="${user.install.root}/temp" /><delete dir="${user.install.root}/wstemp" /></target></project>'
antAgent = AdminControl.makeObjectName(AdminControl.queryNames('WebSphere:*,type=AntAgent,process=dmgr'))

str = String(fileContent)
bytes = str.getBytes()

AdminControl.invoke_jmx(antAgent, 'putScript', [String('cleanup.xml'),bytes], jarray.array(['java.lang.String', '[B'], String))

AdminControl.invoke_jmx(antAgent, 'invokeAnt', [jarray.array([], String), String('cleanup.xml'), String('cleanup')], jarray.array(['[Ljava.lang.String;', 'java.lang.String', 'java.lang.String'], String))

fileContent variable is you Ant script, you may have to tweak it a bit more, especially on Windows in order to deal with blocked files/directories.




回答2:


wsadmin.sh can be launched with Jython which is Python with Java.

So you can use Python default classes: import os os.rmdir('/a/b/c')

Also if you are on Unix: import os os.sys('rm -r /a/b/c') or os.system('rm -r /a/b/c')

The above commands will remove directory 'c' in /a/b. Use os.remove('filename') to remove a file.



来源:https://stackoverflow.com/questions/13266875/wsadmin-jython-delete-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!