module - How to execute a jar file on jboss7 startup? -


i have simple java class displays "waiting" text on execution , in "tmscore" java project.

 package com.stock.bo;      public class example {          /**          * @param args          */         public static void main(string[] args) {             // applicationcontext context = new classpathxmlapplicationcontext("applicationcontext.xml");              system.out.println("================================> waiting");         }      } 

i have created tmscore.jar , have set example.class entry point ,of jar file.

then have created module project in c:\jboss\jboss-as-7.1.1\modules\org\tms\main , , pasted jar in same path

then have created module.xml , pasted in same path

module.xml

<?xml version="1.0" encoding="utf-8"?> <module xmlns="urn:jboss:module:1.1" name="org.tms">    <resources>     <resource-root path="tmscore.jar"/>    </resources> </module> 

then have created jboss-deployment-structure.xml in webproject/web-inf directory

<?xml version="1.0" encoding="utf-8"?> <jboss-deployment-structure>   <deployment>     <dependencies>       <module name="org.tms"/>     </dependencies>   </deployment> </jboss-deployment-structure> 

when start server war containing above jboss-deployment-structure.xml, in console showing deployed tmscore.jar

but "waiting" text in jar not displayed on console

my requirement should "================================> waiting" on console once jboss started up

or else can 1 can suggest how make jar execute on starting jboss server?

btw using jboss7.1

if right it's because jboss doesn't execute library, loads classes contained in jar file. putting main function , generating executable jar not help.

if goal have global module on server, suggest these modifications:

  1. create module (as have done)
  2. declare dependency in jboss-deployment-structure.xml (as have done)
  3. declare global module on server, loaded once jboss. edit configuration file standalone.xml , modify section:

    <subsystem xmlns="urn:jboss:domain:ee:1.0">     <global-modules>         <module name="org.tms" />     </global-modules> </subsystem> 

now have module have classes loaded once. need have 1 instance of example class, suggest use singleton:

public class example {      // 1 instance     private static example instance;      // private constructor avoid creation of other instances of class     private example()     {         system.out.println("================================> waiting");     }       public static example getinstance()     {         if(instance == null)         {             instance = new example();         }         return instance;     }  } 

then use in projects on server

example ex = example.getinstance(); 

will give existing instance (or create 1 first time).

notice: can't try, no guarantee that work.


edit: maybe small modification of example class can make run during classes loading:

public class example {      // 1 instance     private static example instance = new example();      // private constructor avoid creation of other instances of class     private example()     {         system.out.println("================================> waiting");     }      public static example getinstance()     {         return instance;     }  } 

again: not tested.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -