Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading a java class on server startup

 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to call a java class on server startup. The java class/jar would be doing some activities like setting System Properties and stuff.

Is it possible to call a java class during startup. I came across java agents, have anybody used this kind of approach. I refer another post in coderanch on same topic Link.

It would be helpful if someone elaborates more.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say server do you mean the actual machine the program is running on, or the servlet container / application server to which the application is deployed?
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Application server where my application is deployed. I use Glassfish as app server
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it sort of depends on what you want/need to do exactly.
For instance you could use a load-on-startup Servlet, or an @Startup annotated EJB to execute some initialization / configuration stuff, but one might be more suitable than the other.
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

I want to configure my Jdbc-Resources on server level. I intend to read my connection details from a property file and set it on the system properties during startup.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, in that case I wouldn't take this route at all.
You should probably look at the DataSource class and tutorial and how to configure one on GlassFish.
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your efforts.

I have a work around where I have property-placeholders in my domain.xml for Jdbc-resource-pool and I set the values on System-property on the admin console.

So, it becomes a two-step process. My trying to link some java class on my server startup, which would eventually set the values.

So my end-user would be unaware of the change.

Any thoughts on this.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Sridhar wrote:
So my end-user would be unaware of the change.


This I don't quite follow. Are you trying to make your DataSource configurations editable at runtime?
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was configuring my resources on the server. I used javaagent to load a class at start up and worked fine.

Thanks for your response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic