0

속성 파일의 값에 따라 context.xml 및 web.xml 파일의 내용을 업데이트하고 싶습니다. 내 웹 응용 프로그램에서 사용할 수있는 데이터베이스 연결을 설정하고 싶습니다. 이 콘텐츠를 역동적으로 추가 할 수 있습니까? 나는 현재 어떤 업데이트 내가Maven Plugin을 사용하여 파일 내용을 업데이트 할 수 있습니까?

<resource-ref> 
    <description>Env1 Database Connection</description> 
    <res-ref-name>jdbc/Env1</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

<resource-ref> 
    <description>Env2 Database Connection</description> 
    <res-ref-name>jdbc/Env2</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

<resource-ref> 
    <description>Env3 Database Connection</description> 
    <res-ref-name>jdbc/Env3</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

<resource-ref> 
    <description>Env4 Database Connection</description> 
    <res-ref-name>jdbc/Env4</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

다음 한 내 web.xml 파일에서 내 POM

<build> 
    <finalName>ROOT</finalName> 
    <filters> 
     <filter>src/main/resources/environmentProperties/env1.properties</filter> 
     <filter>src/main/resources/environmentProperties/env2.properties</filter> 
     <filter>src/main/resources/environmentProperties/env3.properties</filter> 
     <filter>src/main/resources/environmentProperties/env4.properties</filter> 
    </filters> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>${maven-war-plugin-version}</version> 
      <configuration> 
       <webResources> 
        <resource> 
         <directory>${basedir}\src\main\resources\META-INF</directory> 
         <filtering>true</filtering> 
         <targetPath>META-INF</targetPath> 
         <includes> 
          <include>**\context.xml</include> 
         </includes> 
        </resource> 
       </webResources> 
       <warSourceDirectory>src/main/webapp</warSourceDirectory> 
       <webXml>src/main/webapp/WEB-INF/web.xml</webXml> 
      </configuration> 
     </plugin> 
    </plugins> 

</build> 

에 다음 빌드 섹션을 사용하여 진행 한

는 정말 수하는 것을 선호 environmentProperties 폴더에 필요한만큼 많은 특성 파일을 가지고 web.xml (및 context.xml) 파일을 갱신하여 각 환경에 적절한 항목을 추가하십시오. 이것이 가능한가.

아파치 벨로 시티는 루핑 구조를 보았지만,이를 활용할 수있는 메이븐 플러그인이 있는지 모르겠습니다.

덕분에, 폴

답변

0

나는 템플릿을하고 렌더링 할 stringtemplatehttp://www.stringtemplate.org/를 사용하여 행운이 있었다. 현재의 maven 버전을 기반으로 Docker 파일을 생성하는데 사용하기 때문에 새로운 jar 버전을 릴리스 할 때마다 업데이트하지 않아도됩니다.

dockerfile(jar) ::= << 

FROM anapsix/alpine-java 
MAINTAINER saisols.com 
RUN mkdir /opt/app 
ADD . /opt/app 
WORKDIR /opt/app 
CMD ["java", "-jar", "<jar>.jar"] 

>> 

그것은 실행할 단지 올바른 이름으로 CMD 광고를 렌더링 :

  <plugin> 
       <groupId>com.webguys</groupId> 
       <artifactId>string-template-maven-plugin</artifactId> 
       <version>1.1</version> 
       <configuration> 
        <templates> 
         <template> 
          <directory>${basedir}/src/main/resources/templates</directory> 
          <name>dockerfile</name> 
          <target> 
           ${basedir}/target/Dockerfile 
          </target> 
          <properties> 
           <jar>${project.build.finalName}</jar> 
          </properties> 
         </template> 
        </templates> 
       </configuration> 
       <executions> 
        <execution> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>render</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

이 플러그인 구성이 dockerfile 걸린다.

이것은 정확하게 당신이 요구하는 것이 아니지만, 당신이하고 싶은 일을하기 위해이 전략을 사용했습니다.

당신은 등록 정보 파일을 읽을 수 있습니다 (그래서 당신은 POM에 속성 하드 코드하지 않으며, 그래서 당신은 프로파일 또는 무엇에 따라 다른 파일을 읽을 수 있습니다) http://www.mojohaus.org/properties-maven-plugin/usage.html

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>properties-maven-plugin</artifactId> 
    <version>1.0.0</version> 
    <executions> 
     <execution> 
     <phase>initialize</phase> 
     <goals> 
      <goal>read-project-properties</goal> 
     </goals> 
     <configuration> 
      <files> 
      <file>etc/config/dev.properties</file> 
      </files> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
에서 properties-maven-plugin과를
+0

다시 연락해 주셔서 감사합니다. 현재 내가 가지고있는 접근법은 필터 섹션에 항목을 추가하여 특성 파일에서 값을 읽을 수 있도록 허용합니다. 하지만 내가 선호하는 것은 폴더 (src/main/resources/environmentProperties)를 지정하고 Maven을 사용하고 모든 파일을 읽으므로 다른 파일이 추가되면 POM을 수정할 필요가 없습니다. 또한 web.xml 및 context.xml 내에서 등록 정보 파일의 수에 따라 정확한 수의 항목을 작성하기로 결정했습니다. 여기에는 템플릿을 지정하는 루핑이 필요합니다. – ceepan

+0

StringTemplate의 웹 사이트를 살펴보십시오. 템플릿 엔진이며 원하는대로 할 수 있습니다. http://www.stringtemplate.org/ - 또한 속성 플러그인이 와일드 카드를 사용할 수 있다고 생각하지만 여러 파일을 반드시 가져옵니다. – mikeb

관련 문제