1

i cant import class from ejb module to web module. the ejb class is in package: jsf in module ejb and i want to import it to web module package: jsf

import jsf.DaneOsobowe; - dosent work

what do i wrong?

master 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>

web 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>
wezeweze
  • 131
  • 1
  • 3
  • 13
  • Using EJB as a dependency is extremely strange. I wouldn't be surprised if your .war is generated without .ejb in libs somehow. You should probably put the shared components into a separate shared .jar library, and reference it from both .ejb and .war. – Anton Koscejev May 30 '16 at 07:38
  • how can i do that? im a begginer i java – wezeweze May 31 '16 at 04:30

1 Answers1

0

Sorry, I'm not very familiar with EAR+EJB things, because for most cases I encountered it was gross over-complication. However, if that's what you need to use...

Check out an answer explaining them in some detail.

Basically EJB is supposed to contain implementations for some interfaces that are defined elsewhere. WAR will not know what implementations it'll get at runtime, it just knows the interfaces, so it should depend on the interfaces. Let's call those interfaces API and you'll get the following project structure:

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

Where:

  1. API contains just interfaces (don't specify packaging, it'll default to jar)
  2. EJB depends on API to implement some/all interfaces
  3. WAR depends on API to use them (e.g. via interface injection points)
  4. EAR depends on WAR and EJB to bundle the two into final archive

If this is too complex for your use case, you can start with just WAR containing everything and refactor later. You can deploy .war to any application server and even just containers without full application server functionality.

Community
  • 1
  • 1
Anton Koscejev
  • 4,603
  • 1
  • 21
  • 26