Installing configuration data in Java

Hello,

I’m a newbie regarding Orekit used through Java. I was following this guide in order to install the configuration data: Orekit Tutorials – Downloads

The line
DataProvidersManager manager = DataProvidersManager.getInstance();
gives me a problem related to getIstance:

“The method getInstance() is undefined for the type DataProvidersManager”.

How could I overcome this?

Thank you in advance.

Hi Federica,

Sorry, this part of the tutorial documentation has not been corrected.
Since Orekit 10.1, the correct code is:

DataProvidersManager manager = DataContext.getDefault().getDataProvidersManager();

Regards,
Pascal

File orekitData = new File("C:\\Users\\<user>\\eclipse-workspace\\orekit-data");
LazyLoadedDataContext lazy = new LazyLoadedDataContext();
lazy.getDataProvidersManager().addProvider(new DirectoryCrawler(orekitData));
UTCScale utc = lazy.getTimeScales().getUTC();
AbsoluteDate date = new AbsoluteDate(2021, 10, 27, 16, 11, 0.0, utc);

I’m able to retrieve orekit data (to be used for instance for other purposes, as for instantiating the AbsoluteDate in the example), but only in the way shown in the code lines above. Is there a more generic way to load only ONCE all the orekit data (at the start of execution of my Java code) and then forget about it?
So that - for example - when I later call TimeScalesFactory.getUTC(), Orekit will automatically return me the desired time scale without needing to use workaround UTCScale utc = lazy.getTimeScales().getUTC().

I had to implement this code since I tried the one you sent me but it gives me an error related to the fact that it cannot access to the class methods

Thank you in advance,
Regards.

Hi,

You are close to the goal :slight_smile:
At the start of your application, just add the data provider to the default data context like this

File orekitData = new File("C:\\Users\\<user>\\eclipse-workspace\\orekit-data");
DataContext.getDefault().getDataProvidersManager().addProvider(new DirectoryCrawler(orekitData));

then you will be able to use anywhere in your code all available factories ( CelestialBodyFactory, FramesFactory, GeoMagneticFieldFactory, GravityFieldFactory, TimeScaleFactory ) that use the default context.

Regards.
Pascal

1 Like

Many thanks for your reply, but I still have problems unfortunately.

It seems like a problem with your project in the IDE.
Try refreshing the project or organizing the imports (Ctrl+Shift+O in Eclipse).
If it doesn’t work, add the following statement to force the import

import org.orekit.data.DataContext;