有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法在Amazon linux上通过JPype启动JVM

我使用JPype从python测试中调用Java代码,并通过JPype启动JVM

我使用自定义类路径和默认JVM路径执行。在错误中,它能够找到类路径和默认jvm路径

这是启动JVM时出现的错误

jvmpath = '/usr/lib/jvm/java-1.8.0-amazon-corretto/jre/lib/amd64/server/libjvm.so', classpath = ['/home/jaiadi/test_new/*'], ignoreUnrecognized = False
convertStrings = False

    def startJVM(*args, **kwargs):
        """
        Starts a Java Virtual Machine.  Without options it will start
        the JVM with the default classpath and jvmpath.
    
        The default classpath is determined by ``jpype.getClassPath()``.
        The default jvmpath is determined by ``jpype.getDefaultJVMPath()``.
    
        Parameters:
         *args (Optional, str[]): Arguments to give to the JVM.
            The first argument may be the path the JVM.
    
        Keyword Arguments:
          jvmpath (str):  Path to the jvm library file,
            Typically one of (``libjvm.so``, ``jvm.dll``, ...)
            Using None will apply the default jvmpath.
          classpath (str,[str]): Set the classpath for the JVM.
            This will override any classpath supplied in the arguments
            list. A value of None will give no classpath to JVM.
          ignoreUnrecognized (bool): Option to ignore
            invalid JVM arguments. Default is False.
          convertStrings (bool): Option to force Java strings to
            cast to Python strings. This option is to support legacy code
            for which conversion of Python strings was the default. This
            will globally change the behavior of all calls using
            strings, and a value of True is NOT recommended for newly
            developed code.
    
            The default value for this option during 0.7 series is
            True.  The option will be False starting in 0.8. A
            warning will be issued if this option is not specified
            during the transition period.
    
    
        Raises:
          OSError: if the JVM cannot be started or is already running.
          TypeError: if an invalid keyword argument is supplied
            or a keyword argument conflicts with the arguments.
    
         """
        if _jpype.isStarted():
            raise OSError('JVM is already started')
        global _JVM_started
        if _JVM_started:
            raise OSError('JVM cannot be restarted')
    
        args = list(args)
    
        # JVM path
        jvmpath = None
        if args:
            # jvm is the first argument the first argument is a path or None
            if not args[0] or not args[0].startswith('-'):
                jvmpath = args.pop(0)
        if 'jvmpath' in kwargs:
            if jvmpath:
                raise TypeError('jvmpath specified twice')
            jvmpath = kwargs.pop('jvmpath')
        if not jvmpath:
            jvmpath = getDefaultJVMPath()
    
        # Classpath handling
        if _hasClassPath(args):
            # Old style, specified in the arguments
            if 'classpath' in kwargs:
                # Cannot apply both styles, conflict
                raise TypeError('classpath specified twice')
            classpath = None
        elif 'classpath' in kwargs:
            # New style, as a keywork
            classpath = kwargs.pop('classpath')
        else:
            # Not speficied at all, use the default classpath
            classpath = _classpath.getClassPath()
    
        # Handle strings and list of strings.
        if classpath:
            if isinstance(classpath, str):
                args.append('-Djava.class.path=%s' % _handleClassPath([classpath]))
            elif hasattr(classpath, '__iter__'):
                args.append('-Djava.class.path=%s' % _handleClassPath(classpath))
            else:
                raise TypeError("Unknown class path element")
    
        ignoreUnrecognized = kwargs.pop('ignoreUnrecognized', False)
        convertStrings = kwargs.pop('convertStrings', False)
    
        if kwargs:
            raise TypeError("startJVM() got an unexpected keyword argument '%s'"
                            % (','.join([str(i) for i in kwargs])))
    
        try:
            _jpype.startup(jvmpath, tuple(args),
>                          ignoreUnrecognized, convertStrings)
E                          TypeError: function takes exactly 5 arguments (4 given)
jpype/_core.py:212: TypeError
___

我启动JVM的代码如下所示

            JAR_CLASSPATH = ['/home/jaiadi/test_new/*']
            jpype.startJVM(jpype.getDefaultJVMPath(), classpath=JAR_CLASSPATH, convertStrings=False)


知道我为什么会出现param错误吗


共 (0) 个答案