-->

application.xml is not generated correctly while s

2019-07-04 06:23发布

问题:

I always encounter the following situation while "Run On Server" on my mavenized EAR project.

Situation

If I take the following steps on my EAR project:

  • mvn clean install
  • Run on Server

... will lead to:

The application.xml generated by Maven will be correct:

<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
  <display-name>com.company.fbps.api.impl.ear</display-name>
  <module>
    <ejb>com.company.fbps.api.impl.ejb-0.0.1-SNAPSHOT.jar</ejb>
  </module>
</application>

While the EJB project "com.company.fbps.api.impl.ejb" is a maven dependency of the EAR project:

(in "com.company.fbps.api.impl.ejb" pom.xml)

<dependency>
    <groupId>com.company.fbps.api.impl.ejb</groupId>
    <artifactId>com.company.fbps.api.impl.ejb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>ejb</type>
</dependency>

... but the application.xml generated by Run on Server is incorrect:

The Oracle WebLogic Server Plugin will generate a application.xml to:

...\.metadata\.plugins\org.eclipse.core.resources\.projects\com.company.fbps.api.impl.ear\beadep\fbp_local_test\com.company.fbps.api.impl.ear\split_src

.... having the wrong EJB jar name:

<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
  <display-name>com.company.fbps.api.impl.ear</display-name>
  <module>
    <ejb>com.company.fbps.api.impl.ejb.jar</ejb>
  </module>
</application>

So in this process some integration is not aware of the fact that Maven generates a different ejb.jar name and this is not used for "Run on Server".

Workaround

I found a workaround to get it somehow running. If you say "Maven - Update Project Configuration ..." before "Run on Server" it works once. But will be corrupt again after the next build.

Used Plugins

  • Oracle WebLogic Server Tools for Eclipse 11.1.1.8.0
  • m2e - Maven Integration for Eclipse 1.0.100.20110804-1717

Question

Do you have any idea how to correct this situation without using my workaround?

回答1:

I use the weblogic-maven-plugin to deploy my ear to weblogic. Below is a sample configuration from the pom. this should be on your ear project pom. Make sure the dependencies are added right, the dependencies are not available from maven repository. I had to manually install them and as well the wlfullclient.jar had to be built using the weblogic jarbuilder Once you have the configuration set right create a maven build run configuration with goal weblogic:deploy. This should get the artifact deployed to your weblogic server.

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>2.9.1</version>
<configuration>
  <adminServerHostName>localhost</adminServerHostName>
      <adminServerPort>7001</adminServerPort>
  <userId>${username}</userId>
  <password>${password}</password>
  <upload>false</upload>
  <remote>false</remote>
  <verbose>false</verbose>
  <debug>true</debug>
  <targetNames>${server}</targetNames>
  <exploded>false</exploded>
  </configuration>
<dependencies>
  <dependency>
   <groupId>weblogic</groupId>
   <artifactId>weblogic</artifactId>
   <version>${weblogic.version}</version>
     </dependency>
 <dependency>
  <groupId>weblogic</groupId>
  <artifactId>wlfullclient</artifactId>
  <version>${weblogic.version}</version>
</dependency>
<dependency>
 <groupId>weblogic</groupId>
 <artifactId>webservices</artifactId>
 <version>${weblogic.version}</version>
    </dependency>
<dependency>
 <groupId>org.apache.xmlbeans</groupId>
 <artifactId>xmlbeans</artifactId>
 <version>2.3.0</version>
   </dependency>
  </dependencies>
 </plugin>


回答2:

This message:

Caused By: java.io.FileNotFoundException: 
C:\<ECLIPSE WORKSPACE PATH>\.metadata\.plugins\org.eclipse.core.resources\.projects\<EAR PROJECT NAME>\beadep\<SERVER DOMAIN NAME>\<EAR PROJECT NAME>\<WAR NAME>

is caused by a conflict between META-INF/application.xml and .settings/org.eclipse.wst.common.component. I'm using angle brackets to represent a variable in the path, since those parts will be different for everyone.

<EAR PROJECT NAME> is determined from org.eclipse.wst.common.component:

<wb-module deploy-name="<EAR PROJECT NAME>">

<WAR NAME> is also determined from org.eclipse.wst.common.component:

<dependent-module archiveName="<WAR NAME>"......

The war name in application.xml's web-uri tag should match the archiveName attribute from org.eclipse.wst.common.component:

If they are not the same, Eclipse gets confused and doesn't know where to look for your war file. Note that this only applies when using Eclipse to build your project. You can change either file to fix the problem, however, since Eclipse creates org.eclipse.wst.common.component, it might change without you knowing, so I suggest changing application.xml.