سؤال

انا املك مافن المشروع ، مع 4 مكونات الويب والمثابرة ، المشتركة وغيرها.

الأشياء ذات الصلة قبالة بلدي بوم الملفات:

الوالد بوم:

<groupId>com.test</groupId>
<artifactId>test</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
    <module>components/TestWeb</module>
    <module>components/TestOther</module>
    <module>components/TestPersistence</module>
    <module>components/TestCommon</module>
</modules>


<build>
    <defaultGoal>package</defaultGoal>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <dependentWarExcludes>
                    **/hibernate.cfg.xml,**/sql-map-config.xml,**/web.xml,WEB-INF/classes/META-INF/**
                </dependentWarExcludes>
            </configuration>
        </plugin>
     </plugins>
 </build>

بوم المشترك:

<modelVersion>4.0.0</modelVersion>
<artifactId>test-common</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>

ثبات بوم:

<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-persistence</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>


<dependencies>
  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

ويب بوم:

<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-web</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TestWeb</name>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>

  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>


  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-persistence</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>


  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-other</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>

ربما كسرت شيئًا ما في النسخة واللصق ، لكن XML صالح.

  • عندما أقوم بتشغيل حزمة MVN ، المشروع ملف الحرب لم يتم إنشاؤه ، ولكن يتم إنشاء جميع حزم المكونات وتشكيلها جيدًا.
  • إذا ، إذن ، أركض mvn war:war, ، يتم إنشاء ملف الحرب فارغ.

كيف يمكن إصلاح هذا؟

هل كانت مفيدة؟

المحلول

وجود ملحقات إضافية في مشروع الجذر لا يعمل. يمكنك تكوين الإضافات هنا ، مثل هذا

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

لكن لا يزال يتعين الرجوع إليها في المشاريع الفرعية لتكون نشطة (باستثناء المكونات الإضافية التي تشكل جزءًا من العملية الافتراضية ، مثل Maven-Compiler-Plugin و Maven-Resource-Plugin).

لذلك إما أن تنقل تكوين حرب plugin إلى pluginManagement في مشروع الجذر وتشمل

<build>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1</version>
        <execution>
            <goals>...</goals>
        </execution>
    </plugin>
</build>

في مشروع الحرب الخاص بك أو تقوم بنقل التكوين بأكمله إلى الحرب.

ملاحظة إضافية: تأكد من محاذاة ترتيب الوحدات النمطية الموجودة في الجذر مع علاقات التبعية بين المشاريع (في حالتك فقط عكس الطلب).

نصائح أخرى

لقد قمت بإنشاء بنية مشروع مماثلة ولصق POMs التي قدمتها ولكن لم أستطع إعادة إنتاج المشكلة. ادارة mvn package من بوم التجميع يعمل فقط كما هو متوقع:

$ mvn package 
[INFO] Scanning for projects...
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Unnamed - com.test:test:pom:0.0.1-SNAPSHOT ............ SUCCESS [5.819s]
[INFO] Unnamed - com.test:test-common:jar:0.0.1-SNAPSHOT ..... SUCCESS [3.343s]
[INFO] Unnamed - com.test:test-persistence:jar:0.0.1-SNAPSHOT  SUCCESS [0.136s]
[INFO] Unnamed - com.test:test-other:jar:0.0.1-SNAPSHOT ...... SUCCESS [0.079s]
[INFO] Unnamed - com.test:test-web:war:0.0.1-SNAPSHOT ........ SUCCESS [1.899s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

وينتج النتيجة التالية:

$ tree .
.
├── components
│   ├── TestCommon
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-common-0.0.1-SNAPSHOT.jar
│   ├── TestOther
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-other-0.0.1-SNAPSHOT.jar
│   ├── TestPersistence
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-persistence-0.0.1-SNAPSHOT.jar
│   └── TestWeb
│       ├── pom.xml
│       ├── src
│       │   └── main
│       │       └── webapp
│       │           ├── index.jsp
│       │           └── WEB-INF
│       │               └── web.xml
│       └── target
│           ├── maven-archiver
│           │   └── pom.properties
│           ├── test-web-0.0.1-SNAPSHOT
│           │   ├── index.jsp
│           │   ├── META-INF
│           │   └── WEB-INF
│           │       ├── classes
│           │       ├── lib
│           │       │   ├── test-common-0.0.1-SNAPSHOT.jar
│           │       │   ├── test-other-0.0.1-SNAPSHOT.jar
│           │       │   └── test-persistence-0.0.1-SNAPSHOT.jar
│           │       └── web.xml
│           └── test-web-0.0.1-SNAPSHOT.war
└── pom.xml

لذلك يجب أن يكون لمشكلتك شيئًا ما يتعلق بمشروع الحرب نفسه ، أو هيكله أو شيء من هذا القبيل. يرجى إظهار هيكله وإخراج Maven عند التشغيل war:war عليه.


بالمناسبة ، إليكم كيف يجب أن تبدو POM عادةً في بنية متعددة الأنواع:

<project>
  <modelVersion>4.0.0</modelVersion>
  <!--groupId>com.test</groupId--> <!-- unnecessary, you inherit it -->
  <artifactId>test-web</artifactId>
  <packaging>war</packaging>
  <!--version>0.0.1-SNAPSHOT</version--> <!-- unnecessary, you inherit it -->
  <parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId> <!-- DRY, use built-in properties -->
      <artifactId>test-common</artifactId>
      <version>${project.version}</version> <!-- DRY, use built-in properties -->
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-persistence</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-other</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</project>

شيء آخر ، التكوين المكون الإضافي للحرب من المشروع الأصل هو ورث (يمكنك التحقق من ذلك عن طريق التشغيل help:effective-pom في وحدة الويب) ولكن من المنطقي تكوينه في وحدة الويب نفسها.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top