• Post Reply Bookmark Topic Watch Topic
  • New Topic

loading database info in a web app  RSS feed

 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
What I want to achieve is to automatically make a war file and load database info (such as host, port, password,...) to my app.
I do not want to hardcode the info in java code; instead it better be in a config file.
I'm using maven (I'm new to this) for creating the war file so please guide me how this is commonly done.

My guess is there could be at least 4 possibilities:
- using jndi
- use environment variables which is problematic because if you have many apps, the variables might collide and also I need to set them before running my app server.
- passing parameters to maven like "mvn package -Ddb_host="10.4.4.2"
- use pom.xml.

I've also read about jndi but I do not know how it is supposed to know where the context.xml file...
thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't put them in your pom.xml. You don't want your database password under source control.

There's two more options you didn't mention. Have the property file be independent from your application and include the classpath to point to it when you deploy on the server. And the most common one - use a server side datasource so you don't need to have the credentials in your app at all. T his way, you give them once to the server and let it hold/encrypt them for you.
 
Niiraj Patel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kourosh, Second option suggested by Jeanne is very true.. You should use data-source facility provided by your Java Application Server.You can also put this information in encrypted properties file and also set some flag which tell system to whether to take connection from data-source or manually connect using JDBC..

Regards,
Niraj
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I need to mention that this is NOT for production environment so the data is not critical.
I want to do it automatically by spinning an ec2 instance, so if there must be no manual step.

- regarding suggestion 1, basically you're saying I put the properties in a file. I guess that means you have to copy over the file to the right location depending on what app server you're deploying on or alternatively place it in the app before packaging it.
- regarding using a datasource, can you elaborate please in details?

 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out and share it:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!