python - 解决运行grinder脚本时出现的ImportError : No modules named ,

标签 python jython grinder

我开始使用grinder工具,当我运行我的脚本时,我收到以下错误。

ImportError: No module named net.grinder.script. Grinder

这是我正在尝试运行的脚本

# A minimal script that tests The Grinder logging facility.
#
# This script shows the recommended style for scripts, with a
# TestRunner class. The script is executed just once by each worker
# process and defines the TestRunner class. The Grinder creates an
# instance of TestRunner for each worker thread, and repeatedly calls
# the instance for each run of that thread.

  from net.grinder.script.Grinder import grinder
  from net.grinder.script import Test

# A shorter alias for the grinder.logger.info() method.
  log = grinder.logger.info

# Create a Test with a test number and a description. The test will be
# automatically registered with The Grinder console if you are using
# it.
  test1 = Test(1, "Log method")

# Instrument the info() method with our Test.
  test1.record(log)

# A TestRunner instance is created for each thread. It can be used to
# store thread-specific data.
 class TestRunner:

# This method is called for every run.
 def __call__(self):
    log("Hello World")

每当运行此脚本时,我都会收到导入错误。

我还设置了 CLASSPATH 和 JAVA_HOME 环境变量。谁能帮我吗。

最佳答案

设置类路径有点棘手,在运行上面 Philp 提供的 java 命令之前,我在 mac(10.6.8) 终端上执行了以下操作:

ClassPath 设置:(在终端上依次执行此操作)

    export JAVA_VERSION=1.6
    export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    export GRINDERPATH=/Users/cdname/grinder-3.11
    export CLASSPATH=$GRINDERPATH/lib/grinder.jar:$CLASSPATH
    export PATH=$JAVA_HOME/bin:$PATH
    java -classpath $CLASSPATH net.grinder.Grinder

我将其添加到/etc/launchd.conf 中,然后运行 grep -E "^setenv"/etc/launchd.conf | grep -E "^setenv"/etc/launchd.conf | xargs -t -L 1 launchctl

在grinder.properties文件中设置:grinder.useConsole = false

现在运行 .py 文件:

     java -Dgrinder.script=csaTest.py net.grinder.Grinder

关于python - 解决运行grinder脚本时出现的ImportError : No modules named ,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23465922/

相关文章:

python - 线程1 :EXC_BAD_INSTRACTION

java - 在 Eclipse 或 PyCharm 中将 java 包导入到 jython 项目中

java - 磨床连接错误

用于 Grinder 脚本的 IDE

python - 在 python 中使用 scipy curve_fit 拟合 boxcar 函数的问题

python - 如何在 PySNMP 中进行单个 GETNEXT 查询

python - 解决了: Why does importing a Python library throw a syntax error?

java - Jython:无法在 Java 中导入 python 函数

networking - 模拟高延迟/间歇性网络连接

python - 肉欲有没有条件规定?