2013-05-02 3 views
0

"TMSCore"Java 프로젝트에서 실행시 "대기중인"텍스트를 표시하는 간단한 Java 클래스가 있습니다.jboss7 시작시 jar 파일을 실행하는 방법은 무엇입니까?

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"); 
     } 

    } 

TMSCore.jar을 만들었고이 jar 파일을 내 jar 파일의 진입 점으로 설정했습니다.

는 그때는 C이 프로젝트 모듈을 만들었다 : \ 제이 보스 \ 보스로서의 7.1.1 \ 모듈 \ 조직 \ TMS 메인 \ 난이

후, 같은 경로에있는 단지를 붙여 을 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> 

그때 난 내 webproject/WEB-INF 디렉토리에 JBoss에 배포-structure.xml을 만들었을 Module.xml

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

내가 TMSCore.jar

하지만 전개의 전시가 내 "대기"내 항아리에 텍스트 콘솔

에 표시되지 않습니다 내 콘솔에서 JBoss에 배포-structure.xml 이상 포함하는 나의 전쟁으로 서버를 시작합니다

내 요구 사항은 "jaoss가 내 콘솔에서"대기해야합니다. "==============================================================================

또는 다른 사람이 jboss 서버를 시작할 때 jar를 만드는 방법을 제안 할 수 있습니까? JBoss의 라이브러리를 실행하지 않기 때문에 나는 경우 BTW 내가 JBOSS7.1

답변

1

을 사용하고

바로 그것이 단지 로드jar 파일에 포함 된 클래스입니다. 따라서 주 기능을 넣고 실행 파일을 생성하면 jar 도움이되지 않습니다. (같은 (이미했던 것처럼)

  1. 이 모듈을 만들고
  2. jboss-deployment-structure.xml에 의존로 선언 : 당신의 목표는 서버에서 전역 모듈을 가지고있는 경우

    , 나는 당신에게 이러한 수정을 제안 이미 완료 했음)

  3. 서버에서 전역 모듈로 선언하므로 JBoss에 의해 한 번만로드됩니다. 구성 파일 standalone.xml을 편집하고 섹션을 수정 :

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

이제 클래스가 한 번만로드가 모듈을 가지고있다.

Example ex = Example.getInstance(); 

당신을 다시 줄 것이다 서버에 모든 프로젝트에서 사용하는 그런

public class Example { 

    // The only one instance 
    private static Example instance; 

    // Private constructor to avoid creation of other instances of this class 
    private Example() 
    { 
     System.out.println("================================> waiting"); 
    } 


    public static Example getInstance() 
    { 
     if(instance == null) 
     { 
      instance = new Example(); 
     } 
     return instance; 
    } 

} 

: 나는 당신이 당신의 Example 클래스의 인스턴스가 하나만 있어야합니다, 나는 당신을 제언은 싱글 톤을 사용하는 기존 인스턴스 (또는 처음 인스턴스 생성).

알림 : 시도 할 수 없으므로 작동하지 않을 수도 있습니다.


편집 :은 아마 Example 클래스의 작은 수정은 또한 클래스 로딩시에 실행되도록 할 수 있습니다

public class Example { 

    // The only one instance 
    private static Example instance = new Example(); 

    // Private constructor to avoid creation of other instances of this class 
    private Example() 
    { 
     System.out.println("================================> waiting"); 
    } 

    public static Example getInstance() 
    { 
     return instance; 
    } 

} 

다시 : 테스트하지.

1

jar를 실행할 수는 없지만 단일 메소드로 시작 메소드를 실행할 수 있습니다.

@Startup 
@Singleton 
public class FooBean { 

    @PostConstruct 
    void atStartup() { ... } 

    @PreDestroy 
    void atShutdown() { ... } 

} 

이것은 응용 프로그램 시작 및 종료시 발생합니다. 거기에서 필요한 기능을 호출 할 것입니다.

http://docs.oracle.com/javaee/6/tutorial/doc/gipvi.html

관련 문제