Use orekit-master-data.zip inside an exported jar file

Hello,
i am new to using orekit and facing a very basic problem.
I am currently using the orekit library in my software but I am facing issues with integrating the orekit-master-data.zip file into the exported jar file. I am using the ZipJarCrawler to add the data to the dataprovidermanager but this does not seem to work. The zip file is placed inside the src folder in my eclipse project and works fine from within the ide but as soon as I export it as a jar and try to run it I get an exception that says

Caused by: java.lang.NullPointerException
at org.orekit.frames.TopocentricFrame.(TopocentricFrame.java:72)

Here is my code.

URL url =
FileUtils.class.getClassLoader().getResource("/src/orekit-data-master.zip");
DataProvidersManager manager = DataProvidersManager.getInstance();
manager.addProvider(new ZipJarCrawler(new File(url.toURI().getPath())));
Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
Constants.WGS84_EARTH_FLATTENING,
earthFrame);
GeodeticPoint geodeticP = new GeodeticPoint(latitude, longitude, altitude); // Create location point
// Topocentric frame for the ground station.
TopocentricFrame station = new TopocentricFrame(earth, geodeticP, stationName);

Can someone help me out?

Thankyou

Hi @saiprasadbarke,

Welcome to the Orekit community !

I think the problem comes from the line:

URL url = FileUtils.class.getClassLoader().getResource("/src/orekit-data-master.zip");

I am not a specialist of jar production but here you’re using a relative path that your IDE understands but that the jar does not know.
I would suggest you to not try to embark the “orekit-data” in the jar, since you may want to update the data later without recompiling the project.
A common way is to put the “orekit-data” in a separate directory (your home directory for example) and use something like:

File home       = new File(System.getProperty("user.home"));
File orekitData = new File(home, "orekit-data-master.zip");
DataProvidersManager manager = DataProvidersManager.getInstance();
manager.addProvider(new ZipJarCrawler(orekitData));

There are some examples of this in the tutorials, like this one on propagation.

Now if you really want to have the orekit-data into the jar you’ll have to wait for someone more knowledgeable than me to answer :slight_smile:

Maxime

Hello Maxime,

Thank you for your idea. I can still use that as an alternative in the meantime.

I would not recommend embedding the orekit-data-master.zip inside a jar, and even not recommend to use it directly.
The first reason is that the zip/jar archive file format exhibit an overhead when extracting small files from big archives, as the central directory that describes the file structure is at the end of the archive. So for example in orekit-data, even if you only need to access the 41 lines text file tai-utc.dat and even if it is at the start of the archive, you will need to parse the complete multi-megabytes archive to reach the central directory. This will happen for all files you extract from it (and there are several hundred of small files in the MSAFE sub-folder in the archive). The archive is big because in addition to these numerous small files, it contains also four bigger files, the JPL ephemerides, the Earth gravity field, the Earth Orientation parameters for IAU-1980 and the Earth Orientation Parameters for the IAU-2000. The orekit-data-master.zip file is intended only as a way to distribute these hundreds of files easily, but users are expected to extract the content in some directory on their computer (or server, or phone, or whatever) and load only the files they need without being forced to skip through millions of bytes that will be ignored at the end.

The second reason for avoiding use of the zip archive is that orekit-data contains data that must be updated from time to time. The more stringent example are the Earth Orientation Parameters that are updated by IERS every week (either by completing the big finals.all and finals2000A.all files or by adding new small files like Bulletin A). Updating these data within a zip archive is a pain. It is much easier to updated the files in a folder on a regular file system.

Anyway, if your use case is really to embed the data within your code, the key is to make sure the classpath of your application does contain the data. This is done either by putting the archive at the top of the jar (maven copies it automatically everything that is in the src/resources folder there for you), or by adding a separate jar in addition to the application jar and set up a launcher script so it launches the java virtual machine with both the application jar and the data jar (see the option -classpath in the java command line). Once again, beware in this case that your application will only use data that will quickly become out of date.

1 Like

Hello Luc,

is it possible to download the specific files from the internet using NetworkCrawler? I can easily download the orekit-master-data.zip using the NetworkCrawler but this creates a significant overhead every time the application is run.

Regards,

Sai

Sorry to re-vitalize this thread but I’m currently undertaking a same effort. Please see this link for a more detailed post.

Ultimately my question is, would using an uncompressed jar file potentially work and remove the concern of the overhead?

No, the overhead is related to the zip format, and a jar file is simply a zip file with some
mandatory structure (typically a manifest file).

@luc I appreciate the insight. I am going to continue working the issue, but the ultimate goal is to leverage the gradle distribution plugin which can provide an application archive. This provides the following directory structure and eliminates the concern of orekit-data being zipped or in the jar. The challenge is getting the java code to work correctly, because in the coding structure the data is located at src/dist/orekit-data which is different then the distribution.

root
|--lib
|    |--projectjars*.jar
|
|--bin
|    |--projectName.sh
|    |--projectName.bat 
| 
|--orekit-data