This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Mavenize an existing enterprise ejb application containing web project, ejb module. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Mavenize an existing enterprise ejb application containing web project, ejb module." Watch "Mavenize an existing enterprise ejb application containing web project, ejb module." New topic
Forums: Ant, Maven and Other Build Tools EJB and other Java EE Technologies
Author

Mavenize an existing enterprise ejb application containing web project, ejb module.

Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Hi,

I am trying to mavenize an existing enterprise application and this application has EJB, MDB and MQs.
As far as the folder structure is concerned,
it has a project that creates an ear file, and has one for project for web and another project for EJBs. there is one more project that holds some property file.

I am trying to mavenize this this application, so that I am able to create an ear of application containing the war of web project, jars of property project and ejb project and I am badly stuck.
I will greatly appreciates if anybody can provide me some help.

Thanks,
Shiv


Vishwakarma, Shiv
SCJP 1.4, SCWCD 5
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 123
    
    5

I'm assuming you are trying to go from ANT to Maven? The most important thing to remember about Maven projects is that Maven projects are good at build 1 thing and that's it. If you remember this, you'll have an easier time going from the ANT world (which is an xml scripting language) to the Maven world (which is a configurable build tool) With that said, your goal is to divide your code into multiple projects. Have one Maven project build the WAR, have another Maven project build the EJB-JAR, have another build the JAR of the properties. Finally, you can have a Maven EAR project which has <dependency> on all the rest to construct the EAR.


Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Did you see this post that is similar: http://www.coderanch.com/t/614391/tools/practice-handle-multiple-module-Maven


JBoss In Action
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Hi Peter,

I saw that post later and have replied to that as well...
anyways I have created the project, but there is one small problem.
I some custom jars that should be included in the project, so for that I have installed them to my local maven repository and have declared them as dependency in parent POM.
now the problem is those jars are getting bundled twice, first time as part of ear, and secondly they are getting bundled in war as well...which i do not want.
Can you help me in this regard.

Shiv
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

For this...
I have created a parent maven project, and created module project for ear, which has dependent projects for war and ejb,
There is another java project (properties) that holds some configuration items.
Now I have made ejb and war project as module of parent project.
and properties project is also made as module.
now I am facing this problem of jars getting added twice one in ear and other in war...
how can i prevent jars from getting added to war...i think it is happening because war pom is inheriting properties from parent pom.

please suggest..
Shiv
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 123
    
    5

On the WAR, you should be able to configure the dependency to be provided. This should prevent it from being added to the WAR and instead be part of the EAR.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

You should declare dependencies in your parent POM only if they apply to every child project. In your case, this is not true. I suspect that you are confusing the two POM hierarchies provided by Maven:

The master/submodule hierarchy lets you define a master POM, which when built, causes the submodules to also be built. As an example, a master POM can be used to build a EAR, and it could reference several submodules which build the WARs and JARs that will be packaged in the EAR.

The parent/child hierarchy lets you place common plugins, dependencies, etc. for artifacts for a specific type so that you don't have to include those in very artifact POM. For example, I have a parent POM that has a dependencies JUnit, log4j and a few other JARs that I use in every java project. This POM doesn't itself build anything (its package type is "pom"). Every JAR I build uses this POM as its parent. Similarly, I have a parent POM for every WAR that exposes a REST web service; this POM includes the Jersey JARs an a few others as dependencies, and has the first parent POM I mentioned as its parent so that I pick up those dependencies and plugins.

Note that these two concepts are independent - if I have a master POM A, and a submodule POM B, I do not have to state in B's POM that A is its parent (because it isn't). In the one case where I actually used a master POM (I usually frown on using them, I think that using independent POMs and a tool like Jenkins to order your builds is the better way to got), the only directive in the master pom as the list of submodules, and if the submodule references a parent POM, it never was the master POM. In other words, something like this:

Parent POM Z defines plugins and dependencies
Master POM X references:
- submodule A, no parent POM
- submodule B, parent is Z
- submodule C, parent is Z
- submodule D, parent is Z
- submodule E, no parent POM

Note that none of the submodules reference X as their parent.
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Thanks everyone, I am able to mavenize my application now and it is working properly.
But there is something more for which I will require your assistance.
There are some third party jars which are used in the application, but now there is a constraint that they cannot be installed into maven local repository.
And now the only way that i seem to have is to keep the jars in projects lib directory, and configure my pom to refer it directly from there.
But i am not able to it. appreciate if anybody can help me with it or suggest me if there is any better way.

Thanks,
Shiv
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 123
    
    5

Where is this "constraint" coming from? They absolutely can be installed into the local repository. Better yet they should be installed onto your company's Maven repository (nexus, artifactory, etc.) so others can automatically pull them down when they need to work on the project. The JARS can be added to nexus or artifactory manually (login and follow their process to upload the JARS) or you can add them to the repository via an `mvn` command on your machine.
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Thanks Michael, but the problems is we do not have the source code of the jars, and thats why they cannot be installed on company's maven repository, as they are asking for the source code.
We even tried generating the code from jars using decompiler, but that does not solves the problem...as they don't provide 100% complete code.
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 123
    
    5

So using a system scoped dependency won't work?

<dependencies>
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/some.jar</systemPath>
</dependency>
</dependencies>
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

So you are saying that some other department (perhaps corporate IT) is running the Nexus server and that they won't allow anything to be deployed to it unless the source is provided? That is somewhat short-sighted. Most of the artifacts we have in the thirdparty repository don't have source files. But then we store all binaries there, even OS and application installation images. If it is source, it goes into Subversion, if it is binary it goes into Nexus. Our build process disallows getting files from any other locations.

By the way, you could always set up your own Nexus server, place the files into it, and proxy your corporate Nexus repository.
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Hi Peter,

It is not about the third party jars, it is about the some application jars that were developed internally long back, and now we do not have the source code. All we have is just the jars that are used in the current application that we are trying to mavenize.
Can you please tell if there is a way we can place these jars in the application source code, and make our pom.xml to refers to these jars. That way we can avoid installing these jars in any repository and can use them in project also.
I think using system path we can do something like this, but I am not getting how to use it.
Any help or suggestions is highly appreciated.

Thanks
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

Shiv Vishwakarma wrote:Hi Peter,

It is not about the third party jars, it is about the some application jars that were developed internally long back, and now we do not have the source code. All we have is just the jars that are used in the current application that we are trying to mavenize.
Can you please tell if there is a way we can place these jars in the application source code, and make our pom.xml to refers to these jars. That way we can avoid installing these jars in any repository and can use them in project also.
I think using system path we can do something like this, but I am not getting how to use it.
Any help or suggestions is highly appreciated.

Thanks

I still don't see why they would not be allowed on the corporate Nexus. You should really make it a point to your architect/project manager, and if there is a good reason, do it as Michael instructed.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Can't I do something like this...
use mvn deploy:deploy-file to deploy the jars in the project local directory which i can use as a maven local repository

mvn deploy:deploy-file -Durl=file:///C:/<project folder>/repo -Dfile=C:/jars/somejar.jar -DgroupId=somejar-DartifactId=somejar -Dpackaging=jar -Dversion=1.0.0

and then add below code to pom.xml

<repositories>
<!--other repositories if any -->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
</repositories>

and have dependency declaration like below:

<dependency>
<groupId>somejar</groupId>
<artifactId>somejar</artifactId>
<version>1.0.0</version>
</dependency>


doing above things I am able to achieve the desired results, but for few jars it is not working and still says not able to artifacts.

Please suggest.

Thanks,
Shiv
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

"deploy" is always to a remote repository such as nexus. "install" is for a local repository. Doing a "deploy" to a file URL works only if there is a repository manager that manages that location, and if you add that repository to your poms for your projects.
 
GeeCON Prague 2014
 
subject: Mavenize an existing enterprise ejb application containing web project, ejb module.