I am stuck in a scenario where I have to Pass the Sub report as a parameter to my Jasper Report Object.I am new to Jasper and Spring Boot. Because When I pass the sub-report in parameter list locally it work fine but when i Deploy it on server It says my fileName.jrxml not found.
It is not the Parameter Issue. Its file Path issue. You need to load the jrxml file in the form of stream other wise on server due to the file path resolving in Springboot some time create complex paths which usually not found or people make mistakes defining path.
You have to follow some steps.
Create folder in Resources directory of you project
Place your jrxml there
Load your jrxml file as Stream
InputStream stream=getClass().getResourceAsStream("/yourdir/yourfile.jrxml");
Compile the Stream into jasperReport Obeject
JasperReport subReportJasperCompileManager.compileReport(stream);
Now Pass it in Param List with the same name in your Parent Report
parameters.put("sub_report_setting", subJasperReportSetting);
Here are the 3,4 and 5th steps.
InputStream stream=getClass().getResourceAsStream("/yourdir/yourfile.jrxml");
JasperReport subReportJasperCompileManager.compileReport(stream);
parameters.put("sub_report", subJasperReportSetting);
Related
I already got add the resource to the classpath using
<additionalBuildArg>-H:IncludeResources=.*/kubernetes_auth.crt$</additionalBuildArg>
<additionalBuildArg>-H:Log=registerResource:verbose</additionalBuildArg>
When I build the image I can see in the log that if I add it
ResourcesFeature: registerResource: classes/kubernetes_auth.crt
But when I try to read the resource with the following code that works in Java, it returns null
InputStream is = KubernetesResource.class.getResourceAsStream("/kubernetes_auth.crt");
I have tried with these variants but same returns null
Thread.currentThread().getContextClassLoader().getResourceAsStream("/kubernetes_auth.crt");
ClassLoader.getSystemClassLoader().getResourceAsStream("/kubernetes_auth.crt");
getClass().getResourceAsStream("classes/kubernetes_auth.crt");
Versions of quuarkus 0.13.3 and 0.14.0 and Graal rc14, rc15, rc16
As you discovered, you need to specify the resource to be loaded.
As of Quarkus 1.8.0 (and for some time before), you can list resources that should be available for the native image to load using a property:
quarkus.native.resources.includes=kubernetes_auth.crt
The property supports a comma-separated list of files. The syntax for this list is described in the configuration reference for building native images: https://quarkus.io/guides/building-native-image#configuration-reference
I am using Spring boot application. I have this structure in my resource folder
resources
|__customers
|__retail
I have to pass the path to this folder to one of the beans for writing files.
The names of the files are dynamic so I cannot pass a predefined value to the file.
To do this I tried
#value(${classpath:resources/customer/retail} )
Resources resource;
// Also tried
ResourceLoader loader = new FileSystemResourceLoader();
ResourceUtils.getURL(filePathDump).getPath().getClass().getResource(
"indexingData/publication/analysis/dump"
);
// and several other options
but it shows throw file not found or resource not found Exception, Now I checked the way path are defined for each one of them and I am positive they were all specified correctly
I need a way to pass this path to a folder in resources. Please help
you can autowire org.springframework.core.io.ResourceLoader and then get file as follows:
resourceLoader.getResource("classpath:customer/retail/someFile.txt")
I have to implement spring cloud config for an existing project where i have an use case to handle
Here Some property files are referred by other property files like
logging.propFile=classpath:/cfg/xyz.properties and these property files are used in multiple places like
Properties property = new Properties();
property.load(new FileInputStream(propsPath));
logger = somefactory.createfactory(property.get("logging.propFile")); and this factory creation is defined in a different jar.
If i move all property files in git repo files i mentioned will not be available in class path and if i go for code change a lot of code change is involved.What is the best way to handle this situation.
Is there any way to refer one property file to another in spring cloud config .
Spring Cloud Config server allows for reading static files through HTTP. So you can put your references properties file into the configuration git repository and reference them through http://<configserver_url>/*/*/<branch_name>/xyz.properties. This only works when your code can handle URLs, so the FileInputStream in your example would not do it.
See https://cloud.spring.io/spring-cloud-config/multi/multi__serving_alternative_formats.html and https://cloud.spring.io/spring-cloud-config/multi/multi__serving_plain_text.html.
Also note the resolvePlaceholders query parameter that defaults to true.
We are using this for keeping our logback.xml configuration in the config server by setting logging.config: http://<configserver_url/*/*/master/logback.xml?resolvePlaceholders=false
I want to fetch values dynamically from properties so I have implemented one poc. In that poc I have declared one object with value in mule expression component. After that I am fetching the value key from properties file. It is showing exceptions while testing the application.
Exception MSG: Root Exception stack trace: unresolvable property or identifier: $
EX-1:
flowVars.deptCode=21432143;
property3=${flowVars.deptCode};
EX-2:
property3=${21432143};
In the above two examples ex-2 has worked fine and ex-1 has failed .
Please let me know if anyone have clarity on that.
Thanks,
Praveen
Mule is using Spring Properties which can be kept in a seperate properties file and then retrieved/used in your application via ${propertyName}.
A property placeholder is used to define where you keep those properties.
Ex 1 is not possible because properties are not aware at all of any variables or properties inside of your Mule application.
Another issue is that those files will be loaded when the application is started.
If you change the value of a property a restart of your application is needed, so your approach isn't going to work.
More info in the docs here:
https://docs.mulesoft.com/mule-user-guide/v/3.8/configuring-properties
You can use dataweave script to dynamically read values from property file
#[dw("p(flowVars.deptCode)")]
I'm using Spring 3 and would like to get the path to a folder I have created under the WebContent folder. I want to create a File instance there.
A real path to the file under webapp root can be obtained using ServletContext.getRealPath().
Note that this method may return null if the concept of real path has no sense in your deployment configuration (for example, application is deployed as an unpacked .war), in this case you can't create a file there.
An instance of ServletContext in Spring can be autowired.