Using the SNAP Java API in an external JAVA program

Hi, I’m trying to use the SNAP API in one of my own Java programs, but when trying to open a product (Sentinel-1 SLC) using ProductIO, I end up with a Null pointer. I suspect that the reader for the file format cannot be found?

I have a succesful build of the SNAP engine and desktop, as well as the S1 Toolbox. The file opens just fine in the desktop build, but not using my own code. Do I have to do anything special to initialize a product reader mechanism? My code is as follows:

import java.io.IOException;
import org.esa.snap.core.datamodel.Product;
import org.esa.snap.core.dataio.ProductIO;

public class MyTest {
public static void main(String[] args) {
Product prod;
try {
prod = ProductIO.readProduct(“S1B_IW_SLC__1SDV_20181223T165126_20181223T165153_014172_01A561_A693.SAFE/manifest.safe”);
int numBands = prod.getNumBands();
System.out.println("numBands = " + numBands);
} catch (IOException e) {
;
}
}
}

Can anyone give me a clue? Thanks!

You code looks fine.
I think it is just a problem of the classpath.
You need to add the need one from the s1tbx to your start configuration.

I think reading this guide will help you:
How to create a bundle of SNAP jars for the usage on the classpath - SNAP Wiki

That’s it. My classpath was incomplete, thank you!