2016-05-30 32 views
0

我不能從ejb模塊導入類到web模塊。 ejb類在包中:jsf在模塊ejb中,我想將其導入到Web模塊包中:jsf如何從另一個模塊導入類maven

import jsf.DaneOsobowe; - 劑量工作

我錯了什麼?

主POM:

<?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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>jsf</groupId> 
    <artifactId>PAW</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 
    <name>PAW</name> 

    <modules> 
    <module>PAW-ear</module> 
    <module>PAW-web</module> 
    <module>PAW-ejb</module> 
    </modules> 

    <dependencyManagement> 
    <dependencies> 

     <dependency> 
     <groupId>jsf</groupId> 
     <artifactId>PAW-ejb</artifactId> 
     <version>1.0</version> 
     <type>ejb</type> 
     <scope>compile</scope> 
     </dependency> 

     <dependency> 
     <groupId>jsf</groupId> 
     <artifactId>PAW-web</artifactId> 
     <version>1.0</version> 
     <type>jar</type> 
     <scope>compile</scope> 

     </dependency> 
    </dependencies> 
    </dependencyManagement> 
</project> 

EJB POM:

<?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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <artifactId>PAW</artifactId> 
    <groupId>jsf</groupId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <groupId>jsf</groupId> 
    <artifactId>PAW-ejb</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>ejb</packaging> 

    <name>PAW-ejb</name> 

    <properties> 
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>4.3.1.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>unknown.binary</groupId> 
     <artifactId>hibernate-jpamodelgen-4.3.1.Final</artifactId> 
     <version>SNAPSHOT</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <version>7.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>jsf</groupId> 
     <artifactId>PAW-ejb</artifactId> 
     <type>ejb</type> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <configuration> 
      <source>1.7</source> 
      <target>1.7</target> 
      <compilerArguments> 
      <endorseddirs>${endorsed.dir}</endorseddirs> 
      </compilerArguments> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-ejb-plugin</artifactId> 
     <version>2.3</version> 
     <configuration> 
      <ejbVersion>3.1</ejbVersion> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <version>2.6</version> 
     <executions> 
      <execution> 
      <phase>validate</phase> 
      <goals> 
       <goal>copy</goal> 
      </goals> 
      <configuration> 
       <outputDirectory>${endorsed.dir}</outputDirectory> 
       <silent>true</silent> 
       <artifactItems> 
       <artifactItem> 
        <groupId>javax</groupId> 
        <artifactId>javaee-endorsed-api</artifactId> 
        <version>7.0</version> 
        <type>jar</type> 
       </artifactItem> 
       </artifactItems> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    <repositories> 
    <repository> 
     <id>unknown-jars-temp-repo</id> 
     <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name> 
     <url>file:${project.basedir}/lib</url> 
    </repository> 
    </repositories> 
</project> 

網絡POM:

<?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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <artifactId>PAW</artifactId> 
    <groupId>jsf</groupId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <groupId>jsf</groupId> 
    <artifactId>PAW-web</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>PAW-web</name> 

    <properties> 
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>org.primefaces</groupId> 
     <artifactId>primefaces</artifactId> 
     <version>5.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>5.2.2.Final</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>4.3.1.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate.javax.persistence</groupId> 
     <artifactId>hibernate-jpa-2.1-api</artifactId> 
     <version>1.0.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>unknown.binary</groupId> 
     <artifactId>mysql-connector-java-5.1.23-bin</artifactId> 
     <version>SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.1.0.Final</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>org.primefaces.extensions</groupId> 
     <artifactId>primefaces-extensions</artifactId> 
     <version>4.0.0</version> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>7.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>jsf</groupId> 
     <artifactId>PAW-ejb</artifactId> 
     <type>ejb</type> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <configuration> 
      <source>1.7</source> 
      <target>1.7</target> 
      <compilerArguments> 
      <endorseddirs>${endorsed.dir}</endorseddirs> 
      </compilerArguments> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.3</version> 
     <configuration> 
      <failOnMissingWebXml>false</failOnMissingWebXml> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <version>2.6</version> 
     <executions> 
      <execution> 
      <phase>validate</phase> 
      <goals> 
       <goal>copy</goal> 
      </goals> 
      <configuration> 
       <outputDirectory>${endorsed.dir}</outputDirectory> 
       <silent>true</silent> 
       <artifactItems> 
       <artifactItem> 
        <groupId>javax</groupId> 
        <artifactId>javaee-endorsed-api</artifactId> 
        <version>7.0</version> 
        <type>jar</type> 
       </artifactItem> 
       </artifactItems> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    <repositories> 
    <repository> 
     <url>http://repository.primefaces.org/</url> 
     <id>PrimeFaces-maven-lib</id> 
     <layout>default</layout> 
     <name>Repository for library PrimeFaces-maven-lib</name> 
    </repository> 
    </repositories> 
</project> 
+0

使用EJB作爲依賴是非常奇怪的。如果你的.war在某些庫中沒有.ejb的話,我不會感到驚訝。您應該將共享組件放入單獨的共享.jar庫中,並從.ejb和.war中引用它。 –

+0

我該怎麼做?我是一個begginer我java – szkut

回答

0

對不起,我不是很熟悉EAR + EJB的東西,因爲我遇到的大多數情況都是嚴重的併發症。然而,如果這就是你需要使用...

退房an answer explaining them in some detail

基本上EJB應該包含一些在別處定義的接口的實現。 WAR不知道它在運行時會得到什麼樣的實現,它只知道接口,所以它應該取決於接口。讓我們把這些接口API,你會得到以下項目結構:

parent 
|- api 
|- ejb 
|- war 
\- ear 

其中:

  1. API只包含接口(不指定包裝,它會默認爲JAR)
  2. EJB取決於API來實現一些/所有接口
  3. WAR取決於API使用它們(例如,通過接口注入點)
  4. EAR取決於WAR和EJB兩個捆綁成最終的歸檔文件

如果這對於您的用例來說太複雜了,那麼您可以從包含的所有內容開始,並且稍後重新構造一切。您可以將.war部署到任何應用程序服務器,甚至只是沒有完整應用程序服務器功能的容器。

相關問題