You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by mauro2java2011 <ma...@gmail.com> on 2013/07/11 09:42:01 UTC

how set system properties for datasource into resources.xml from variables environments

hi all . 
I have to set int othe WEB-INF/resources.xml a datasource .

i have deployes tomee into openshift cloud .

But my problem is not a openshift problem.
from openshift i can get the following values from variables environments :

OPENSHIFT_MYSQL_DB_HOST 	
OPENSHIFT_MYSQL_DB_PORT 	
OPENSHIFT_MYSQL_DB_USERNAME 	
OPENSHIFT_MYSQL_DB_PASSWORD 	

--------
now i would create a system properties at tomee startup or web application
startup  for get the properties into my resources.xml  (I WOULD SET SYSTEM
PROPERTIES FROM READ THE VARIABLES ENVIRONMENTS THAT I CAN GET FROM
OPENSHIFT.) 


I would to set: 
mydbmysql.host=$OPENSHIFT_MYSQL_DB_HOST
mydbmysql.port=$OPENSHIFT_MYSQL_DB_PORT
mydbmysql.username=$OPENSHIFT_MYSQL_DB_USERNAME
mydbmysql.password=$OPENSHIFT_MYSQL_DB_PASSWORD

i not know if i have to set into catalina.sh or setenv.bat.
or with JAVA_OPTS=..........

but what is it the syintax correct??

from resources.xml i would declare:

<Resource id="MySQL Database" type="DataSource">
    #  MySQL example
    #
    #  This connector will not work until you download the driver at:
    #  http://www.mysql.com/downloads/api-jdbc-stable.html

    JdbcDriver  com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://${mydbmysql.host}/test
    UserName    ${mydbmysql.username}
    Password     ${mydbmysql.password}
</Resource>

or i can get the values direct from variables environments????????

2) how i can add variables environments at TOMEE startup?  a esample for add
a variable ?????
for example : i would add a variable environment named $MYMESSAGE=Hi to all
user of TOMEE
how i can declare for TOMEE ?
tank you very much
Mauro





--
View this message in context: http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how set system properties for datasource into resources.xml from variables environments

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Ron

if you set the config through environment (let say XXX_URL and XXX_USER and
XXX_PWD) then you can just use placeholders in your resource:

JdbcUrl = ${XXX_URL}
UserName = ${XXX_USER}
Password = ${XXX_PWD}



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-06-17 17:30 GMT+02:00 ron <ro...@gmail.com>:

> This is a very old post I know but is this only for openshift? or is that a
> general thing? Reason I ask is I want to run tomee in a docker container
> and
> have it connect to a postgresql database running in another docker
> instance.
>
> Ron
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4675335.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: how set system properties for datasource into resources.xml from variables environments

Posted by ron <ro...@gmail.com>.
This is a very old post I know but is this only for openshift? or is that a
general thing? Reason I ask is I want to run tomee in a docker container and
have it connect to a postgresql database running in another docker instance.

Ron



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4675335.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: how set system properties for datasource into resources.xml from variables environments

Posted by Romain Manni-Bucau <rm...@gmail.com>.
basically implement org.apache.tomcat:tomcat-catalina/7.0.x
org.apache.catalina.LifecycleListener interface, doing sthg like:

       if (event.getType() == Lifecycle.START_EVENT && event.getSource()
instanceof Host) {

            System.setProperty("xxx", System.getEnv("..."));
        }

then simply activate it in server.xml (you can also set this listener in
META-INF/context.xml of your war but you'll need to listen even INIT_EVENT
and check source is instanceof Context)

Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/7/11 mauro2java2011 <ma...@gmail.com>
>
> you can please wirte a example ?
> let me says that i would add a variable:
>  $MY_MESSAGE= Hi all user tomee
>
> --------------------------------------
> openejb hook, a simple jar with a singleton deployed through
> > <Deployements/> in
> > tomee.xml...)  ?????????????????????????????????????????
> >
> >
>
>
>
> > it is on trunk, for earlier versions the workaround is to add
> > something
> > started before setting the correct system properties (tomcat
> > Listener,
> > openejb hook, a simple jar with a singleton deployed through
> > <Deployements/> in tomee.xml...)
> >
> >
> > *Romain Manni-Bucau*
> > *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> > *Blog:
> > **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
> > *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> > *Github: https://github.com/rmannibucau*
> >
> >
> >
> > 2013/7/11 mauro2java2011 <[hidden email]>
> >
> > > i have think that it is not possible read the variables environment
> > only
> > > with
> > > :
> > >   ${NAME_OF_VARIABLE_ENVIRONMENT}
> > >
> > >
> > > OTher question:
> > >
> > > 2) how i can add variables environments at TOMEE startup?  a esample
> > for
> > > > add
> > > > a variable ?????
> > > > for example : i would add a variable environment named
> > $MYMESSAGE=Hi to
> > > > all
> > > > user of TOMEE
> > > > how i can declare for TOMEE ?
> > > > tank you very much
> > > > Mauro
> > > >
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664219.html
> > > Sent from the OpenEJB User mailing list archive at Nabble.com.
> > >
> >
> >
> >
> >
> > ______________________________________________________________________
> > If you reply to this email, your message will be added to the
> > discussion below:
> >
http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664220.html
> > To unsubscribe from how set system properties for datasource into
> > resources.xml from variables environments, click here.
> > NAML
>
>
>
>
>
>
> --
> View this message in context:
http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664221.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how set system properties for datasource into resources.xml from variables environments

Posted by mauro2java2011 <ma...@gmail.com>.
you can please wirte a example ?
let me says that i would add a variable:
 $MY_MESSAGE= Hi all user tomee

--------------------------------------
openejb hook, a simple jar with a singleton deployed through 
> <Deployements/> in
> tomee.xml...)  ?????????????????????????????????????????
> 
> 



> it is on trunk, for earlier versions the workaround is to add
> something 
> started before setting the correct system properties (tomcat
> Listener, 
> openejb hook, a simple jar with a singleton deployed through 
> <Deployements/> in tomee.xml...) 
> 
> 
> *Romain Manni-Bucau* 
> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* 
> *Blog:
> **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> 
> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> *Github: https://github.com/rmannibucau*
> 
> 
> 
> 2013/7/11 mauro2java2011 <[hidden email]> 
> 
> > i have think that it is not possible read the variables environment
> only 
> > with 
> > : 
> >   ${NAME_OF_VARIABLE_ENVIRONMENT} 
> > 
> > 
> > OTher question: 
> > 
> > 2) how i can add variables environments at TOMEE startup?  a esample
> for 
> > > add 
> > > a variable ????? 
> > > for example : i would add a variable environment named
> $MYMESSAGE=Hi to 
> > > all 
> > > user of TOMEE 
> > > how i can declare for TOMEE ? 
> > > tank you very much 
> > > Mauro 
> > > 
> > 
> > 
> > 
> > -- 
> > View this message in context: 
> >
> http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664219.html
> > Sent from the OpenEJB User mailing list archive at Nabble.com. 
> > 
> 
> 
> 
> 
> ______________________________________________________________________
> If you reply to this email, your message will be added to the
> discussion below:
> http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664220.html 
> To unsubscribe from how set system properties for datasource into
> resources.xml from variables environments, click here.
> NAML 






--
View this message in context: http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664221.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how set system properties for datasource into resources.xml from variables environments

Posted by Romain Manni-Bucau <rm...@gmail.com>.
it is on trunk, for earlier versions the workaround is to add something
started before setting the correct system properties (tomcat Listener,
openejb hook, a simple jar with a singleton deployed through
<Deployements/> in tomee.xml...)


*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/7/11 mauro2java2011 <ma...@gmail.com>

> i have think that it is not possible read the variables environment only
> with
> :
>   ${NAME_OF_VARIABLE_ENVIRONMENT}
>
>
> OTher question:
>
> 2) how i can add variables environments at TOMEE startup?  a esample for
> > add
> > a variable ?????
> > for example : i would add a variable environment named $MYMESSAGE=Hi to
> > all
> > user of TOMEE
> > how i can declare for TOMEE ?
> > tank you very much
> > Mauro
> >
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664219.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: how set system properties for datasource into resources.xml from variables environments

Posted by mauro2java2011 <ma...@gmail.com>.
i have think that it is not possible read the variables environment only with
:
  ${NAME_OF_VARIABLE_ENVIRONMENT} 


OTher question:

2) how i can add variables environments at TOMEE startup?  a esample for
> add
> a variable ?????
> for example : i would add a variable environment named $MYMESSAGE=Hi to
> all
> user of TOMEE
> how i can declare for TOMEE ?
> tank you very much
> Mauro
> 



--
View this message in context: http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217p4664219.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: how set system properties for datasource into resources.xml from variables environments

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm, when i used OpenShift i had (i was using trunk):

<Resource id="jdbc/app">
    JdbcDriver  com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_
MYSQL_DB_PORT}/${OPENSHIFT_MYSQL_DB_USERNAME}
    UserName    ${OPENSHIFT_MYSQL_DB_USERNAME}
    Password     ${OPENSHIFT_MYSQL_DB_PASSWORD}
</Resource>

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/7/11 mauro2java2011 <ma...@gmail.com>

> hi all .
> I have to set int othe WEB-INF/resources.xml a datasource .
>
> i have deployes tomee into openshift cloud .
>
> But my problem is not a openshift problem.
> from openshift i can get the following values from variables environments :
>
> OPENSHIFT_MYSQL_DB_HOST
> OPENSHIFT_MYSQL_DB_PORT
> OPENSHIFT_MYSQL_DB_USERNAME
> OPENSHIFT_MYSQL_DB_PASSWORD
>
> --------
> now i would create a system properties at tomee startup or web application
> startup  for get the properties into my resources.xml  (I WOULD SET SYSTEM
> PROPERTIES FROM READ THE VARIABLES ENVIRONMENTS THAT I CAN GET FROM
> OPENSHIFT.)
>
>
> I would to set:
> mydbmysql.host=$OPENSHIFT_MYSQL_DB_HOST
> mydbmysql.port=$OPENSHIFT_MYSQL_DB_PORT
> mydbmysql.username=$OPENSHIFT_MYSQL_DB_USERNAME
> mydbmysql.password=$OPENSHIFT_MYSQL_DB_PASSWORD
>
> i not know if i have to set into catalina.sh or setenv.bat.
> or with JAVA_OPTS=..........
>
> but what is it the syintax correct??
>
> from resources.xml i would declare:
>
> <Resource id="MySQL Database" type="DataSource">
>     #  MySQL example
>     #
>     #  This connector will not work until you download the driver at:
>     #  http://www.mysql.com/downloads/api-jdbc-stable.html
>
>     JdbcDriver  com.mysql.jdbc.Driver
>     JdbcUrl jdbc:mysql://${mydbmysql.host}/test
>     UserName    ${mydbmysql.username}
>     Password     ${mydbmysql.password}
> </Resource>
>
> or i can get the values direct from variables environments????????
>
> 2) how i can add variables environments at TOMEE startup?  a esample for
> add
> a variable ?????
> for example : i would add a variable environment named $MYMESSAGE=Hi to all
> user of TOMEE
> how i can declare for TOMEE ?
> tank you very much
> Mauro
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/how-set-system-properties-for-datasource-into-resources-xml-from-variables-environments-tp4664217.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>