2014-04-12 12 views
10

Ich möchte EAR>META-INF Ordner eine Datei startup MBEAN(startup-client-service.xml) von meinem EJB>META-INF, sich zu bewegen. Ich habe versucht, mit dem maven-resources-plugin Plugin, aber es kopieren Sie einfach die Datei von EJB>META-INF bis Target in ear Ordner. Aber in gebaut ear die startup-client-service.xml Datei in META-INF nicht verfügbar istWie man eine Datei EAR META-INF Ordner hinzufügen - Maven

Wie kann ich meine Startdatei META-INF in Ohr> META-INF bewegen?

Dies ist die Pom-Datei des Ohrs.

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<parent> 
    <groupId>com.testapp</groupId> 
    <artifactId>my-client-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 

<name>Test app EAR</name> 
<artifactId>my-client-ear</artifactId> 

<packaging>ear</packaging> 

<dependencies> 

    <dependency> 
     <groupId>com.testapp</groupId> 
     <artifactId>my-client-ejb</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
     <type>ejb</type> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>2.8</version> 
      <configuration> 
       <defaultLibBundleDir>lib</defaultLibBundleDir> 
       <modules> 
       </modules> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.6</version> 
      <executions> 
       <execution> 
        <id>copy-resources</id> 
        <phase>validate</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>META-INF</outputDirectory> 
         <resources> 
          <resource> 
           <directory>${project.parent.basedir}/ejb/src/main/resources/META-INF</directory> 
           <filtering>true</filtering> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId> 
             org.apache.maven.plugins 
            </groupId> 
            <artifactId> 
             maven-ear-plugin 
            </artifactId> 
            <versionRange> 
             [2.8,) 
            </versionRange> 
            <goals> 
             <goal> 
              generate-application-xml 
             </goal>           
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore></ignore> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

<profiles> 
    <profile> 
     <id>copy_bundle</id> 
     <properties> 
      <install.dir>${jboss.dir}\server\default\deploy</install.dir> 
     </properties> 
     <build> 
      <plugins> 
       <plugin> 
        <artifactId>maven-antrun-plugin</artifactId> 
        <executions> 
         <execution> 
          <id>Copying bundle to destination folder</id> 
          <phase>package</phase> 
          <goals> 
           <goal>run</goal> 
          </goals> 
          <configuration> 
           <tasks> 
            <copy 
             file="${project.build.directory}/${project.build.finalName}.${project.packaging}" 
             overwrite="true" todir="${install.dir}" /> 
           </tasks> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

unten ist das Projekt greifen Arbeitsplatzanzeige

Here is the project structure

+0

ohne die vollständige Struktur Ihres Projektes und ohne die vollen pom-Dateien ist es schwer zu erraten, was Sie in Ihrem Build tun . – khmarbaise

+0

@khmarbaise Ich aktualisiere die ganze Pom-Datei meines Ohres. Mein Projekt hat grundsätzlich 2 Module. eine ist API und andere ist ejb. – user2771655

Antwort

1

Ich schlage vor, Sie verwenden das Maven Ressourcen-Plugin in der Vorbereitungsphase-Paket die Datei auf dem $ zu kopieren {bauen .directory}/$ {project.artifactId} - $ {project.version}/META-INF-Ordner, der der Ordner ist, aus dem die endgültige EAR-Datei gezippt wird. Das Phase Preparation-Paket ist kurz bevor das EAR gezippt wird.

+0

eine Idee, wenn es eine Möglichkeit gibt, in das Maven-Ear-Plugin einhaken, um etwas auszuführen, nachdem das Plugin die Artefakte kopiert, aber bevor es sie zippt? Ich muss eine Datei hinzufügen, die auf den Manifestdateien des Artefakts basiert. http://goo.gl/gD3Tcu – froginvasion

+0

Sie könnten das Maven-Plug-in entpacken, nachdem das Ohr erzeugt wurde, vielleicht und dann neu packen? Ich habe kein Beispiel zur Hand, aber es ist im Internet weit verbreitet ... – mekondelta

+0

Danke, das wäre in der Tat ein Ansatz. Ich entschied mich dafür, die Datei irgendwo als Teil meines Build-Prozesses zu veröffentlichen/hochzuladen, weil ich diese Datei woanders auf die eine oder andere Weise holen muss (sonst müsste ich das Ohr irgendwo anders auspacken und zu der Datei gehen) – froginvasion

17

Der richtige Weg ist das Hinzufügen von Dateien zu src/main/application anstelle von src/main/resources. Sie können auch eine andere earSourceDirectory Konfiguration angeben.

+0

Das ist die maven-ear-plugin Dokumentation: https://maven.apache.org/plugins/maven-ear-plugin/ear-mojo.html. Dort können wir sehen, dass src/main/application der Standardwert für die Konfiguration von earSourceDirectory ist. –

0
  • Verwenden Sie die Phase "Prozess-Ressourcen" mit dem Ziel, "Ressourcen" (oder mekondelta Vorschlag der Verwendung von "prepare-Paket")
  • das Ausgabeverzeichnis auf $ Set {basedir}/target $/{Projekt .artifactId} - $ {} project.version

Hier ist ein komplettes Beispiel

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-resources-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>copy-resources</id> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory> 
          ${basedir}/target/${project.artifactId}-${project.version} 
         </outputDirectory> 
         <resources> 
          <resource> 
           <directory>${project.parent.basedir}/ejb/src/main/resources/META-INF</directory> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
...