zoukankan      html  css  js  c++  java
  • Jmeter java协议配置文件导入

    一. 方法一

         通过ClassLoader获取当前路径,想在java脚本里读取druid.properties,路径如下

           apache-jmeter

                  --bin

                     --druid.properties

         相关代码:      

     public static void loadProps() {
                  String execPath = JdbcWrapper.class.getClassLoader().getClass().getResource("").getPath();
                  String realPath = execPath.substring(execPath.indexOf(":")+1, execPath.indexOf("!")-16);
                  Properties tempProperties = new Properties();
                  InputStream in = null;
                  try {
                         in = new BufferedInputStream(new FileInputStream(realPath + "druid.properties"));
                         // in = new BufferedInputStream(new
                         // FileInputStream("system.properties"));
                         tempProperties.load(in);
                  } catch (IOException e) {
                         log.error("加载system.properties文件失败", e);
                         throw new RuntimeException("加载system.properties文件失败", e);
                  } finally {
                         if (in != null) {
                                try {
                                       in.close();
                                } catch (IOException e) {
                                       log.error("关闭system.properties文件失败", e);
                                       throw new RuntimeException(
                                                     "关闭system.properties文件失败", e);
                                }
                         }
                  }
                  properties = tempProperties;
           }

    二.方法二 

       通过打包配置文件到jmeter执行jar包的的方式

    1. 代码里调用方式

          

     in = new BufferedInputStream(new FileInputStream("system.properties"));

    2. 将配置文件导入jar包

    由于bin目录并不在jmeter的classpath中,所以需要执行一些额外的工作来把jndi.properties添加到jmeter的classpath中,把jndi.properties打包到jmeter的启动jar包中。jmeter的启动jar包为JMETER_HOME/bin/ApacheJMeter.jar,所以需要把jndi.properties 打包到这个 jar 文件中,或者执行如下操作,打开命令行窗口,并定位到 JMETER_HOME/bin 目录,运行如下命令 jar uf ApacheJMeter.jar jndi.properties

  • 相关阅读:
    安装固态硬盘,小米笔记本13.3
    glut相关函数说明
    qt 显示中文
    简述FPS的计算方法
    【BZOJ3527】【ZJOI2014】—力(FFT)
    【BZOJ3653】【洛谷P3899】—谈笑风生(子弹滞销+长链剖分)
    【COGS2652】—天文密葬法(分数规划+长链剖分)
    【BZOJ3611】【HeOI2014】—大工程(虚树+dp)
    【BZOJ1758】【WC2010】—重建计划(点分治+分数规划)
    【BZOJ4765】—普通计算姬(分块+BIT)
  • 原文地址:https://www.cnblogs.com/onmyway20xx/p/4229267.html
Copyright © 2011-2022 走看看