• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Loading a java class on server startup

 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • 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.
 
Bartender
Posts: 1952
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
Oracle Spring Flex
  • 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: 1952
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
Oracle Spring Flex
  • 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: 1952
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
Oracle Spring Flex
  • 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: 1952
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
Oracle Spring Flex
  • 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.
 
That is a really big piece of pie for such a tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!