schibsted / jslt

JSON query and transformation language
Apache License 2.0
628 stars 119 forks source link

import doesn't work from the command-line: not found error no matter what you do #134

Open PS-davetemplin opened 4 years ago

PS-davetemplin commented 4 years ago
import "utilities.jslt" as utils

{ * : . }

Got error below. File utilities.jslt absolutely, positively, definitely exists.

Exception in thread "main" com.schibsted.spt.data.jslt.JsltException: Cannot load resource 'utilities.jslt': not found
        at com.schibsted.spt.data.jslt.impl.ClasspathResourceResolver.resolve(ClasspathResourceResolver.java:42)
        at com.schibsted.spt.data.jslt.parser.ParserImpl.compileImport(ParserImpl.java:70)
        at com.schibsted.spt.data.jslt.parser.ParserImpl.doImport(ParserImpl.java:590)
        at com.schibsted.spt.data.jslt.parser.ParserImpl.processImports(ParserImpl.java:576)
        at com.schibsted.spt.data.jslt.parser.ParserImpl.compile(ParserImpl.java:93)
        at com.schibsted.spt.data.jslt.parser.ParserImpl.compileExpression(ParserImpl.java:55)
        at com.schibsted.spt.data.jslt.Parser.compile(Parser.java:226)
        at com.schibsted.spt.data.jslt.Parser.compile(Parser.java:62)
        at com.schibsted.spt.data.jslt.Parser.compile(Parser.java:51)
        at com.schibsted.spt.data.jslt.cli.JSLT.main(JSLT.java:33)
larsga commented 4 years ago

I'm sure the file exists, but by default JSLT will only load modules from the classpath. So you have to use the API and give the parser a FileSystemResourceResolver for it to look for files on disk.

PS-davetemplin commented 4 years ago

Thanks for the clarification. As a user I would expect the tool to load import references relative to where the referencing file exists first and foremost. I would also hope relative paths work.

larsga commented 4 years ago

In the general case loading things from the file system could open all kinds of security holes, which we'd rather avoid. We could use the file system resolver in the command-line client, I guess. As you say it would make sense. A question is whether users would then be confused when the library behaves differently from the CLI.

RahulKesharwani353 commented 1 year ago

I'm sure the file exists, but by default JSLT will only load modules from the classpath. So you have to use the API and give the parser a FileSystemResourceResolver for it to look for files on disk.

How to use this API inside my Java Spring boot application. As I have utils.jslt inside my "com.example.demo" folder

larsga commented 1 year ago

@RahulKesharwani353 The API will work the exact same way inside Spring boot as it does outside Spring boot. FileSystemResourceResolver will load from files on the file system. Tbh, I'm not sure what your question is.

RahulKesharwani353 commented 1 year ago

@larsga actually I unable to use import statement inside JSLT expression, and I have no idea how to resolve it. Can you please help to solve this

larsga commented 1 year ago

You need to explain what you're doing. Otherwise nobody can tell what is wrong.

RahulKesharwani353 commented 1 year ago

Hey see !

I have made an template.jslt and importing it on my string image

and this is my folder structure

image

when I execute the code, I am getting the same error

larsga commented 1 year ago

There are two problems.

JSLT will try to load your .jslt file from the classpath, but you haven't placed it on the classpath. You've placed it with the source code. So the .jslt file is not in your .jar file.

The . in the import statement will be interpreted as ., so you won't be able to find the file way down in the folder structure.

To start with, here's what I would do. Move the file to src/main/resources/template.jslt. Then change the import statement to import "template.jslt". Then try again.

If you want to move the file into subfolders of resources then you need to use / to separate the folder names, not ..

RahulKesharwani353 commented 1 year ago

okay cool, Thankyou soo mush, it works.

RahulKesharwani353 commented 1 year ago

Hey @larsga

previous solution works ! But I am stucked again

before building it was working . as I dockerized the project, Import Statement fails lo load the file while running the docker container . here is my target folder image

Here is docker file : image

and here is src folder image

larsga commented 1 year ago

Look inside app.jar (it's just a zip file) to see if utils.jslt is in the top level. If you then import it as "utils.jslt" it should work.

RahulKesharwani353 commented 1 year ago

I guess it is in top level image but still not working

larsga commented 1 year ago

Looks like it's not in the top level, but in BOOT-INF/classes?

sahilsh1 commented 1 year ago

Exception in thread "main" com.schibsted.spt.data.jslt.JsltException: Cannot load resource 'jslt-utils.jslt': not found import "jslt-utils.jslt" as app

let source = .env.source let locale = .env.locale let val = .record

{

}

RahulKesharwani353 commented 1 year ago

hey @sahilsh1 refer to this https://github.com/schibsted/jslt/issues/134#issuecomment-1438081800