I am using EclipseLink as JPA implementation and I am adding these properties in the persistence.xml but I can't see any scripts generated? Where are they supposed to be saved or have I misunderstood this property.
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="both" />
Is it possible to define a script as well that would be run after the tables are created? The same way as a seed script in Rails?
EclipseLink should use "createDDL.jdbc" and place it in the current working directory by default. You can change this by specifying the "eclipselink.create-ddl-jdbc-file-name" property for the file name and "eclipselink.application-location" to change the location.
Related
I have an Ant xml file. In this file I want to set two properties based on the current working directory. The current working directory is always of the form /some/base/dir/SRC/sub/dir.
The first property must be set to the current working directory. The second property must be set to the part of the current working directory up to /SRC.
I can set the first property without any issue using the PWD environment variable , but I cannot figure out the second.
<property name="my.dir" value="${env.PWD}" />
<property name="src.dir" value="{what do I put here?}" />
I've heard this can be done with bash-style string manipulation (e.g. ${PWD%*/SRC}/SRC) using StringOps, but I cannot find any good examples.
One approach is to use the <pathconvert> task, perhaps like this:
<property name="my.dir" value="/some/base/dir/SRC/sub/dir"/>
<pathconvert property="src.dir">
<path path="${my.dir}"/>
<mapper type="regexp" from="^(.*)/SRC" to="\1" />
</pathconvert>
<echo message="src.dir=${src.dir}" />
Which gives:
[echo] src.dir=/some/base/dir
There are other mappers available which might work better for you than regexp.
I have a Spring Project where I am using bean configuration file
beans.xml.Inside the bean Configuration file, i have defined some properties for a PlaceHolder which refers to classPath...While the application is running, the properties are getting loaded from /unknownPath/Dev/Loc1/System.properties
Where
${BUS_ENV}=Dev
${LOCATION1}=Loc1
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>classpath:${BUS_ENV}/lbsprocessor.properties</value>
</list>
</property>
<!-- Force system properties to override any deployed runtime properties -->
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
I didn't specify classpath while running my project in IDE
I don't have those files in my resource folder
There are around 65 such files exists(for various reasons) as Dev/Loc1/System.properties
I am not able to find from which location the properties are getting referred. Even after debugging, I couldn't find out what classpath refers to. Please help me with figuring out
If you are using eclipse IDE right click on your project select properties then select Java Build Path. On first tab Source there is one input named Default Output folder that value is your classpath. Check all your properties files are there in that path.
Referring to your point 2 problems might be in these line
<value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>classpath:${BUS_ENV}/lbsprocessor.properties</value>
You are using classpath for file location which means these properties file have to be in the .war file at /Dev/Loc1/System.properties
If properties files are outside of project may be at system level you can access them like this
<value>file:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>file:${BUS_ENV}/lbsprocessor.properties</value>
eg:
<value>file:/home/testuser/system.properties</value>
I am using Mac OS ,in this we are storing the Configurations as a jar file under
/Library/Java/Extension.So java is directly referring classpath to that location by default.
I have developed a webapplication which is having jsp and java code. Right now I have placed all the key-value into a env/lifecycle specific properties file (like conf-dev.properties,conf-stg.properties,conf-prod.properties).
I want to externalize these properties file so that it can be placed outside of war(without effecting the war).
right now war file is tightly coupled with properties file. if i have to modify any thing i have to build and make war and deploy.
I have very limited access on deployment server machine (only have access for one folder where i can put my configuration files) & deployment process is handled by CI(jenkin & automated script).
I explored on internet and came to know that we can achieve this using spring, would like to know what is the best way to achieve this?
As you are using Spring I suppose you already use PropertyPlaceholderConfigurer. If not you should ;)
The location of a property file can be anything that can be resolved as spring Resource. This includes classpath, servletcontext and also file references as URIs (file:///... For absolute paths)
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${config.file.location}" />
</bean>
If I understand your question, then you can use Class.getResourceAsStream(String) the linked Javadoc says (in part)
This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResourceAsStream(java.lang.String).
The better way to externalize env specific properties is to use "user.home" or "user.dir".
Thanks #Martin F..
Resolved:This is the final one i used and its working fine in dev,stage Env.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="false"/>
<property name="order" value="1"/>
<property name="locations">
<list>
<value>classpath:conf-${cisco.life}.properties</value>
<value>file:///${openshift.home}/data/conf-${cisco.life}.properties</value>
<value>file:${openshift.home}/data/conf-${cisco.life}.properties</value>
</list>
</property>
</bean>.
and i used script action hook in openshift to set the lifecycle on system level.
appname=echo $OPENSHIFT_APP_NAME
case "$appname" in
*dev)export JAVA_OPTS_EXT="${JAVA_OPTS_EXT} -Dcisco.life=dev";
echo "setting up env life dev for " $appname
;;
*stage)export JAVA_OPTS_EXT="${JAVA_OPTS_EXT} -Dcisco.life=stg;
echo "setting up env life as stg for " $appname.
I'm trying to get all files within a directory structure of 3 levels deep.
For example:
- the image a.jpg exists in a folder /images/12/34/
- the image b.jpg exists in a folder /images/56/78
I've tried the outbound-gateway like stated in :
https://github.com/spring-projects/spring-integration-samples/blob/master/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml and http://forum.spring.io/forum/spring-projects/integration/104612-inbound-ftp-polling-sub-directories?p=604430#post604430
My configuration :
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="127.0.0.1"/>
<property name="port" value="21"/>
<property name="username" value="Administrator"/>
<property name="password" value="SgtSpeedy1"/>
<property name="fileType" value="2"/>
<property name="clientMode" value="2" />
</bean>
<int-ftp:outbound-gateway id="gatewayLS"
cache-sessions="false"
session-factory="ftpSessionFactory"
request-channel="inbound"
command="ls"
command-options=""
expression="'/images/*/*'"
reply-channel="toSplitter"/>
<int:channel id="toSplitter" />
<int-stream:stdout-channel-adapter channel="toSplitter" append-newline="true"/>
I've omitted the splitter and just print everything out for testing purposes.
When testing, I do not get any file.
I've tried setting the folder to /images/* and then it returns all images under the 'images' folder but not recursively as stated in the links provided. So folders /12/34 and /56/78 aren't taken into account.
I cannot see what I'm missing. Can anyone help?
P.S. I'm working on Spring Integration 2.2.6 without the option to upgrade to 4.0.2 (newest), because I'm using a framework. Otherwise I'd use the -R option for the gateway!
I just tested with foo/foo/bar/qux.txt and foo/foo/baz/fiz.txt with
<int-ftp:outbound-gateway id="gatewayLS"
session-factory="ftpSessionFactory"
request-channel="inbound"
command="ls"
command-options="-1"
expression="'foo/*/*'"
reply-channel="toSplitter"/>
and it worked fine; as expected...
11:34:55.983 DEBUG [main] ...[Payload ArrayList content=[fiz.txt, qux.txt]]...
(I added the -1 option to just get the filename).
This was using linux ftpd on the server side.
Are you sure the files are in /images and not images? (Or is the user chrooted so / is his home)?
I'm using my context.xml file to set init parameters for my java application, for example:
<Parameter
name="Environment"
description="The environment in which this code is running (e.g. Production, Staging, Development)."
value="Production"/>
I would like to be able to create a parameter who's value attribute is loading from a file. Is there anyway to do this? Should I be using a < Resource > element instead? If so, how do I setup a resource to load the contents of a file? I've tried Google, but I my not understand the context.xml file well enough to know what to look for. Any help is much appreciated!
In application-context.xml add this element
<context:property-placeholder ignore-unresolvable="true" location="classpath*:application.properties"/>
In the file application.properties you can define parameters like this
userName=root
password=123
And then you can use the parameters by this way
<property name="username" value="${userName}"/>
<property name="password" value="${password}"/>