Windchill自定义类如何将log输出到Method server中

/*
* edit by shyang
* 该文件演示将自己写的程序,在Shell里面单独执行时,将打印信息输出到method server中
* 这对于输出日志很有用,不然只能自己单独写日志
* 
*/
package ext;

import wt.method.RemoteMethodServer;
import java.io.IOException;
import java.io.Serializable;


public class Loginms implements wt.method.RemoteAccess, Serializable{

    public static void main(String args[]){
/*
*调用invoke方法时,如果不是调用的是非静态类,this是不可以用的,
*所以请先声明一个示例,然后在普通方法doSomething中调用
*/
    	Loginms loginms= new Loginms();
    	loginms.doSomething("Test if can send message to MS");
    	System.exit(0);
    }
    
    public void doSomething(String arg){
    		Class argTypes[] = {String.class};
    		Object argsValues[] = {arg};
    		try{
/*
* invoke请参考API,里面有详细描述
*/    		
    		RemoteMethodServer remotemethodserver = RemoteMethodServer.getDefault();
    		remotemethodserver.setUserName("wcadmin");
    		remotemethodserver.setPassword("windchill");
    		//静态方法
    		remotemethodserver.invoke("doStaticMethod", "ext.Loginms", null, argTypes, argsValues);
    		//非静态方法
    		remotemethodserver.invoke("doCommonMethod", null, this, argTypes, argsValues);
    	}
    	catch (java.rmi.RemoteException re) {
    		System.out.println(">>>>>>There is somthing wrong!");
    		re.printStackTrace();
    	} 
    	catch (java.lang.reflect.InvocationTargetException ite) {
    		System.out.println(">>>>>>There is somthing wrong!");
    		ite.printStackTrace();
    	}

}
//调用的方法,返回值必须是Boolean型的,其他类型不可以执行
//自己其他的方法,都可以从这里调用
public static Boolean doStaticMethod(String oo){
	System.out.println(">>>>>>>>>>Success in Static Method!>>>> " + oo);
	return new Boolean(true);
}
public Boolean doCommonMethod(String oo){
	System.out.println(">>>>>>>>>>Success in Common Method!>>>> " + oo);
	return new Boolean(true);
}
}

转载于:https://www.cnblogs.com/HeavyMetal/articles/1545915.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值