自定义jar包引用

原始java代码,代码的作用的是根据指定的字符串,生成执行长度的随机字符串

package com;
import java.util.Random;
public class randStr { public String random_len(int length){
String chars= "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz0123456789";
int string_length = ;
String randomstring = "";
for (int i=; i<string_length; i++) {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(chars.length());
randomstring += chars.substring(randomInt,randomInt+);
}
return randomstring;
} public static void main(String[] args) {
String result=new randStr().random_len();
System.out.println(result);
} }

通过main函数,脚本调试成功

然后通过eclipse工具将刚才的代码导出成jar包

注意:导出jar包时,一定要将main主函数删除

    public static void main(String[] args) {
String result=new randStr().random_len();
System.out.println(result);
}

将randStr.jar包导入

开始在BeanShell中引用

通过Beanshell代码引用

import java.util.Random;
public String random_len(int length)
{
String chars= "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz0123456789";
int string_length = ;
String randomstring = "";
for (int i=; i<string_length; i++)
{
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(chars.length());
randomstring += chars.substring(randomInt,randomInt+);
}
return randomstring;
} String result =random_len();
log.info(result);
05-11 20:14