Reputation: 254
I'm new to Java. Having some trouble deploying a web app.
I have an EJB project which I deploy on Glassfish (4.1). I also have a second, JSF WEB application that I deploy to the same server. Though I am making it with the consideration that it will be deployed to a separate server, so it creates it's own InitialContext and so on to access the EJBs.
The web application depends on the EJB project. The dependency is declared in the pom of the web app.
When deploying the web app it also tries to deploy the EJBs from the other project for some reason.
That fails with errors like javax.naming.NameAlreadyBoundException
because the EJBs are already deployed separately on this server.
How can this be fixed, so the EJB dependencies from the WEB app wouldn't be attempted to be deployed?
Update: the solution needed refactoring, so the EJBs wouldn't be depended on.
Original
Project A WEB app
________________ ____________
| + EJBs |<------| WEB stuff |
| + Domain cl. | ------------
| + Remote intf. |
----------------
===========================================
Refactored
_______ ____________
| EJBs |----->| Domain cl. |
------- ------------
| ^
| |
| |
v | WEB app
______________ ____________
| Remote intf. | <---| Web stuff |
-------------- ------------
Upvotes: 0
Views: 69
Reputation: 746
You could give the dependency a scope
of provided
:
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact.some.id</artifactId>
<version>1.0</version>
<type>ear</type>
<scope>provided</scope>
</dependency>
This means that at runtime, the dependency will be provided by the container.
see maven doc:
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
Upvotes: 2