diff --git a/orekit_jpype/orekit_jpype.py b/orekit_jpype/orekit_jpype.py index 2b6c19c1ed30e0ce2977d7984290cce883ccff09..ac8c6782f529320c394794ea41809542489617b3 100644 --- a/orekit_jpype/orekit_jpype.py +++ b/orekit_jpype/orekit_jpype.py @@ -1,20 +1,43 @@ import jpype import jpype.imports # This enables direct import of java classes +from typing import List, Union #import jpype.beans # This creates pythonic versions of getters / setters (as in JCC version) -#from jpype.types import * - import os + +# Get the path of the current file, used for finding the jars directory dirpath = os.path.dirname(os.path.abspath(__file__)) +def initVM(vmargs:Union[str, None]=None, additional_classpaths:Union[List, None]=None): + """ + Initializes the Java Virtual Machine (JVM) for Orekit. + + Args: + vmargs (Union[str, None], optional): Additional arguments to pass to the JVM. Defaults to None. + Example for debugging: vmargs='-Xcheck:jni,-verbose:jni,-verbose:class,-XX:+UnlockDiagnosticVMOptions' + additional_classpaths (Union[List, None], optional): Additional classpaths to add to the JVM. Defaults to None. -def initVM(): - jpype.addClassPath(os.path.join(dirpath, 'jars','*')) + Raises: + FileNotFoundError: If any of the additional classpaths do not exist. - # Launch the JVM + """ + # Set the classpath + if additional_classpaths is not None: + for classpath in additional_classpaths: + if not os.path.exists(classpath): + raise FileNotFoundError(f"Classpath {os.path.abspath(classpath)} does not exist") + jpype.addClassPath(os.path.abspath(classpath)) + + # Add standard orekit jars to the classpath if not jpype.isJVMStarted(): + jpype.addClassPath(os.path.join(dirpath, 'jars','*')) + + # Start the JVM # '-Xcheck:jni','-verbose:jni','-verbose:class' - jpype.startJVM( convertStrings=True) + if vmargs is not None: + jpype.startJVM(*vmargs.split(","), convertStrings=True) + else: + jpype.startJVM( convertStrings=True) else: print("JVM already started, resuming on started JVM") diff --git a/orekit_jpype/pyhelpers.py b/orekit_jpype/pyhelpers.py index ca65e97c6f16effa435eba4b9f1cd3dadee6744f..611befc1f0f8876c68d3ba8184bdd54ed23ea5eb 100644 --- a/orekit_jpype/pyhelpers.py +++ b/orekit_jpype/pyhelpers.py @@ -22,6 +22,11 @@ from datetime import datetime import math import os from typing import List, Union + +import jpype +import jpype.imports +from jpype.types import * + from java.io import File from org.orekit.data import DataProvidersManager, ZipJarCrawler, DirectoryCrawler, DataContext, LazyLoadedDataContext from org.orekit.time import TimeScalesFactory, AbsoluteDate @@ -36,9 +41,7 @@ try: except ImportError: import urllib as urlrequest -import jpype -import jpype.imports -from jpype.types import * + def download_orekit_data_curdir(filename='orekit-data.zip'): """