Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Shiv Vishwakarma
Greenhorn
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
 
Shiv Vishwakarma
Greenhorn
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shiv Vishwakarma
Greenhorn
Posts: 24
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic