Hello,
I was making a sort of hello world example. The task is to read a file saved as a resource in the project and save into an external storage by using StorageFs service (just to get a hang of how the service stores the file in the external storage). The following is the code:
public class Main {
private static final Logger LOGGER = Logger.getLogger("Main");
public static void main(String[] args) {
LOGGER.info("Entered Main");
try {
StorageFs storage = ServiceFactory.getRequiredService(StorageFs.class);
if (storage == null) {
throw new IllegalStateException("Storage service unavailable");
}
LOGGER.info("Storage not null");
try (InputStream in = Main.class.getResourceAsStream("/data.csv");
OutputStream outputStream = storage.store("meter_data")) {
if (in == null) {
// resource missing in the JAR
throw new IllegalStateException("CSV not found in resources");
}
byte[] buf = new byte[8192];
int n = 0;
while ((n = in.read(buf)) >= 0) {
outputStream.write(buf, 0, n);
}
outputStream.flush();
System.out.println("File written successfully");
} catch (IOException e) {
// handle or log
LOGGER.log(Level.SEVERE, "File write ERROR", e); //$NON-NLS-1$
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "ServiceFactory load error:"+ e.getMessage(), e);
}
}
}
I am getting MissingServiceException error while running it. Here is the stack trace:
main SEVERE: ServiceFactory load error:ej.storage.fs.StorageFs
ej.service.MissingServiceException: ej.storage.fs.StorageFs
at java.lang.Throwable.fillInStackTrace(Throwable.java:109)
at java.lang.Throwable.<init>(Throwable.java:43)
at java.lang.Exception.<init>(Exception.java:18)
at java.lang.RuntimeException.<init>(RuntimeException.java:18)
at ej.service.MissingServiceException.<init>(MissingServiceException.java:26)
at ej.service.ServiceFactory.getRequiredService(ServiceFactory.java:213)
at com.mycompany.newhelloworld.Main.main(Main.java:26)
at java.lang.MainThread.run(Thread.java:915)
at java.lang.Thread.runWrapper(Thread.java:388)
Here is the build.gradle.kts:
plugins {
id("com.microej.gradle.application") version "1.3.1"
}
group="com.mycompany"
version="0.1.0-RC+"
microej {
applicationEntryPoint = "com.mycompany.newhelloworld.Main"
}
dependencies {
implementation("ej.api:edc:1.3.7")
implementation("ej.library.runtime:storage-fs:1.2.0")
implementation("ej.library.runtime:storage:1.2.0")
implementation("ej.library.runtime:service:1.2.0")
implementation("ej.library.eclasspath:logging:1.2.1")
implementation("ej.api:fs:2.1.1")
implementation("ej.library.runtime:property:4.2.0")
microejVee("com.nxp.vee.mimxrt1170:vee-port:3.1.0")
}
I have added the following line in configuration>common.properties:
# Storage root directory
ej.storage.fs.StorageFs.root=microej
I have uncommented this line in configuration.properties file for the VEE Port Project:
# Enable the External Resources module (disabled by default).
com.microej.runtime.externalresourceloader.enabled=true
I thought, since the StorageFs was a build in implementation of Storage, I don’t need to specify the implementation in any properties file.
I needed help in understanding what I might be doing wrong (is it even feasible?).
Thanks