java.io.FileNotFoundException using Square Wire to load proto schema

I got an exception when using SchemaLoader to load a proto file.

  1. Here is the detailed exception stack trace:

java.io.FileNotFoundException: /opt/app.jar!/BOOT-INF/lib/spring-boot-3.1.2.jar (No such file or directory)
at java.base/java.io.RandomAccessFile.open0(Native Method) ~[na:na]
at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:344) ~[na:na]
at java.base/java.io.RandomAccessFile.(RandomAccessFile.java:259) ~[na:na]
at java.base/java.io.RandomAccessFile.(RandomAccessFile.java:213) ~[na:na]
at okio.JvmSystemFileSystem.openReadOnly(JvmSystemFileSystem.kt:83) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ZipFilesKt.openZip(ZipFiles.kt:66) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem.toJarRoot(ResourceFileSystem.kt:196) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem.toClasspathRoots(ResourceFileSystem.kt:179) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem.access$toClasspathRoots(ResourceFileSystem.kt:45) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem$roots$2.invoke(ResourceFileSystem.kt:50) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem$roots$2.invoke(ResourceFileSystem.kt:50) ~[okio-jvm-3.9.0.jar!/:na]
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.8.22.jar!/:1.8.22-release-407(1.8.22)]
at okio.internal.ResourceFileSystem.getRoots(ResourceFileSystem.kt:50) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem.(ResourceFileSystem.kt:54) ~[okio-jvm-3.9.0.jar!/:na]
at okio.internal.ResourceFileSystem.(ResourceFileSystem.kt:45) ~[okio-jvm-3.9.0.jar!/:na]
at okio.Okio__JvmOkioKt.asResourceFileSystem(JvmOkio.kt:227) ~[okio-jvm-3.9.0.jar!/:na]
at okio.Okio.asResourceFileSystem(Unknown Source) ~[okio-jvm-3.9.0.jar!/:na]
at com.squareup.wire.schema.CoreLoader.resourceFileSystem_delegate$lambda$0(CoreLoader.kt:34) ~[wire-schema-jvm-5.1.0.jar!/:na]
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.8.22.jar!/:1.8.22-release-407(1.8.22)]
at com.squareup.wire.schema.CoreLoader.getResourceFileSystem(CoreLoader.kt:33) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.squareup.wire.schema.CoreLoader.load(CoreLoader.kt:39) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.squareup.wire.schema.internal.CommonSchemaLoader.load(CommonSchemaLoader.kt:150) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.squareup.wire.schema.Linker.getFileLinker$wire_schema(Linker.kt:95) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.squareup.wire.schema.Linker.link(Linker.kt:117) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.squareup.wire.schema.internal.CommonSchemaLoader.loadSchema(CommonSchemaLoader.kt:105) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.squareup.wire.schema.SchemaLoader.loadSchema(SchemaLoader.kt:77) ~[wire-schema-jvm-5.1.0.jar!/:na]
at com.kernelsoft.modeling.fastgrpc.starter.services.ProtobufImportServiceImpl.loadProtoSchema(ProtobufImportServiceImpl.java:229) ~[fastgrpc-starter-1.0.0-SNAPSHOT.jar!/:na]
at com.kernelsoft.modeling.fastgrpc.starter.services.ProtobufImportServiceImpl.getProtobufSchemaFromContent(ProtobufImportServiceImpl.java:114) ~[fastgrpc-starter-1.0.0-SNAPSHOT.jar!/:na]
at com.kernelsoft.modeling.fastgrpc.starter.services.ProtobufImportServiceImpl.handle(ProtobufImportServiceImpl.java:75) ~[fastgrpc-starter-1.0.0-SNAPSHOT.jar!/:na]
at com.kernelsoft.modeling.ext.components.handler.ImportFileEventHandler.handle(ImportFileEventHandler.java:76) ~[kernelsoft-modeling-ext-components-1.0.0-SNAPSHOT.jar!/:na]
at com.kernelsoft.modeling.ext.components.editingcontext.KsEditingContextEventProcessor.handleInput(KsEditingContextEventProcessor.java:396) ~[kernelsoft-modeling-ext-components-1.0.0-SNAPSHOT.jar!/:na]
at com.kernelsoft.modeling.ext.components.editingcontext.KsEditingContextEventProcessor.doHandle(KsEditingContextEventProcessor.java:335) ~[kernelsoft-modeling-ext-components-1.0.0-SNAPSHOT.jar!/:na]
at com.kernelsoft.modeling.ext.components.editingcontext.KsEditingContextEventProcessor.lambda$handle$2(KsEditingContextEventProcessor.java:266) ~[kernelsoft-modeling-ext-components-1.0.0-SNAPSHOT.jar!/:na]
at org.eclipse.sirius.components.web.concurrent.DelegatingRequestContextRunnable.run(DelegatingRequestContextRunnable.java:40) ~[sirius-components-web-2024.3.3.jar!/:2024.3.3]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

  1. And here is my current method to load proto schema:
private Schema loadProtoSchema(File tempProtoDir, File tempProtoFile) {
    try {
        // Create a file system instance using okio file system
        //  FileSystem fileSystem = FileSystem.SYSTEM;
        //
        //  Create a SchemaLoader instance
        //  SchemaLoader schemaLoader = new SchemaLoader(fileSystem);

        // Use the default nio FileSystem
        java.nio.file.FileSystem fileSystem = FileSystems.getDefault();

        // Create a SchemaLoader
        SchemaLoader schemaLoader = new SchemaLoader(fileSystem);

        // Define the source path (directory containing proto files)
        List<Location> sourcePaths =
            Collections.singletonList(Location.get(tempProtoDir.getAbsolutePath()));

        // If a specific proto file is provided, use it as protoPaths for single proto file handling
        List<Location> protoPaths = tempProtoFile != null
            ? Collections.singletonList(Location.get(tempProtoFile.getAbsolutePath()))
            : Collections.emptyList();

        // Initialize the SchemaLoader with source paths and proto paths
        schemaLoader.initRoots(sourcePaths, protoPaths);

        // Load and return the schema
        return schemaLoader.loadSchema();
    } catch (Exception exception) {
        log.error("Error loading proto schema", exception);
        return null;
    }
}

I have tried two constructors of SchemaLoader which use ikio filesystem and nio filesystem respectively. This error occurred but in both ways.

  1. Here is my working scenario:
    My application is a maven based spring boot project, which will be packaged into a jar file by deployment. While debugging in workspace there was no problem to load schema of proto files. Only after deployment when running through the jar file, this error occurred. I am using Square Wire 5.1.0 version, here are the pom dependencies:
<dependency>
    <groupId>com.squareup.wire</groupId>
    <artifactId>wire-runtime</artifactId>
    <version>5.1.0</version>
</dependency>
<dependency>
    <groupId>com.squareup.wire</groupId>
    <artifactId>wire-schema-jvm</artifactId>
    <version>5.1.0</version>
</dependency>
<!-- Kotlin dependencies -->
<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib</artifactId>
    <version>2.0.0</version>
</dependency>
<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-reflect</artifactId>
    <version>2.0.0</version>
</dependency>

I didn’t find a way to solve it. Can someone please help me to address this problem? Thanks.

New contributor

HelloWorld is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật