I want to create a BIRT report using the POJO Data Source. At this, I have do set the path to my .jar files. During development this is no problem because I have my .jar files in the target folder
However when I build my project, I will create an .ear file. How should I then locate the .jar file?
You should delete classpath from rptdesign file. Classpath is defined in 2 places. You can find it here:
<oda-data-source extensionID="org.eclipse.birt.data.oda.pojo" name="Data Source" id="132">
<list-property name="privateDriverProperties">
<ex-property>
<name>SynchronizeClassPath</name>
<value>true</value>
</ex-property>
<ex-property>
<name>pojoClassPath</name>
<value></value>
</ex-property>
</list-property>
<property name="pojoDataSetClassPath"></property>
</oda-data-source>
Related
Is it possible to create a data source by reading the values from an external file which is not bundled with WAR in spring application.
You can use the #PropertySource annotation to load your db properties and you can load the properties from file location like below:-
#PropertySource("file:${app.home}/db.properties")
reference link here:-
https://www.mkyong.com/spring/spring-propertysources-example/
For XML based configuration sample code could be like below:-
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>${app.home}/db.properties</value>
</list>
</property>
</bean>
you can setup your datasource in any properties file, and then you have to provide the classpath for that file in your catalina.sh where you are running your war.
don't forget to load that property file in in your application.
There are a JAR A and JAR B, both have messages.properties in classpath /
And there is WAR C, which has dependencies on JAR A and JAR B.
And when I start WAR C I can only get i18n message from JAR A or JAR B.
So, how can Spring support multiple messages.properties files in classpath?
BTW, WAR C is a spring boot project, and spring.messages.basename=messages
Problem solved.
According to this question Does Spring MessageSource Support Multiple Class Path?
have to ditch ResourceBundleMessageSource and write a custom implementation of MessageSource (most likely by subclassing AbstractMessageSource) which uses PathMatchingResourcePatternResolver to locate the various resources and expose them via the MessageSource
I make a copy of ReloadableResourceBundleMessageSource and write the code by this guide and problem solved.
Yes, Spring supports loading multiple Properties. But properties should be unique. If we have same properties in the two Properties Files then the file which will be loaded later will override the previous Properties from previous file.
For example, if the Properties file from JAR A has two properties {USERNAME, PASSWORD} and JAR B Properties file also has the same two properties then you'll get {USERNAME, PASSWORD} from the file which is loading later.
You can use wildcard to import all the Property Files with same name on your classpath.
In Spring you can mention different Properties files in the form of Array as follows:
<context:property-placeholder
location="classpath:war.properties,
classpath*:message.properties"
ignore-unresolvable="true"/>
or
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:war.properties</value>
<value>classpath*:message.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
In my IntelliJ project, under the project root, there is a config folder.
This is where various .properties files are located.
Within the application, these are made available to Spring in the standard way, using a propertiesConfigurer.xml file:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:config/${name}.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
The reason they are accessed using 'file', is that eventually they may be external to the deployed jar.
This works, both when running the application, and when running unit tests.
I also wish to access files which are only for use when running tests.
I have placed these under:
test
--- resources
-------META-INF
----------spring
-------------config
I have added this line to the list of locations within the same propertiesConfigurer.xml:
<value>classpath*:META-INF/spring/config/${name}.properties</value>
This is not working. No file or resource exception is being thrown, but none of the properties defined in the test file are being resolved within the application.
Within the IntelliJ Project Settings->Modules, src\test\resources is listed as a context root.
Also, on the file system, under:
...\target\test-classes\META-INF\spring\config
the test property files exist.
What is the correct way to access them?
Thanks
I wrote a Maven plugin which instantiates a Spring context. I want to be able to configure the Spring context using a properties file in the project classpath. In the plugin context XML I have:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:configurator.properties</value>
</property>
</bean>
When I run the proper plugin goal in the Maven project using my plugin, Spring can't read the configurator.properties file from the target/classes folder.
How should I configure my mojo to allow Spring running in my plugin to read the properties file from the project classpath?
I have multiple property files I need to refer to. Below I can refer to two that are on the classpath.
How do I refer to a property file with in a jar file ?
<bean id="placeholderConfig" name="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/my_test.properties</value>
<value>classpath:config/some_other.properties</value>
</list>
</property>
If the JAR is in the classpath, then you can reference the properties file inside just like any other resource. Just specify the location of the properties file within the JAR file.