Skinny War file with Maven in Eclipse - eclipse

I have a Maven project 'Project A' which contains dependencies. I have a requirement to abstract the dependencies from this project into another project called 'Shared Lib' so that I can make what is called a "Skinny War" file from Project A. Both these files will then be uploaded to a Weblogic server.
However, I am having a lot of difficulties being able to get Project A to pick up the dependencies in Shared Lib.
Some guidance on how I should approach this problem would be much appreciated.
Thanks!

I would split the maven project into two modules. If we call one module SharedLib and the second one Skinny War then you will have something like:
<modules>
<module>sharedLib</module>
<module>skinnyWar</module>
</modules>
In the shared lib module pom.xml you will fill all the dependencies required for the project. In the skinnyWar module your first dependency in the list will be for the sharedLib module. You might need to setup the assembly plugin for the sharedLib module to create a jar in the package phase and you are good to go ;)
Some food of though - do you really want to do this? An important part about using maven is to take care of dependencies for you and package a easy to deploy jar. If you create two different jars it would cause all other kinds of troubles like - were both deployed. Are we using an older version of the dependencies etc.

Related

Having a jboss-deployment-structure.xml with dependencies in common libraries

I have a small issue that is annoying me somewhat. We have built numerous commons libraries for all our applications deployed on JBoss/Wildfly. Some of those common libraries have dependencies to JBoss modules.
The common way for EAR and WAR files is to add a jboss-deployment-structure.xml to the archive, which contains a bunch of module-dependencies.
I have tried several times to add a jboss-deployment-structure.xml to my Commons JARs so that the WAR/EAR-archives that import them will automatically see the dependencies the JAR has as it's own, however, no attempt of doing this renders the correct result.
Has anyone successfully managed to declare "transitive" dependencies in JAR-files packed inside of WAR-files without having to redeclare the same dependencies in the WAR-file's jboss-deployment-structure.xml?
Any examples would be greatly appreciated!
You can use the MANIFEST.MF to declare dependencies for a JAR. The line will look something like:
Dependencies: org.some.module, org.another.module
The Maven plugin maven-jar-plugin will add it for you as part of the build process.
Your best option is to create your own JBoss module to hold all your common JARs used by all your different applications. This module would have it's own module.xml file declaring the dependencies on the JARs contained within it and one any libraries on other JBoss modules. These custom modules can also be versioned and applications can also depend on specific versions.

multi-project sbt build - package all dependent JARs in one directory

I have a multi-project SBT build: some projects are dependent on each other, some are dependent on third-party JARs, and there's a "main" project which depends on everything .
When I sbt package it, I get one JAR in each target/ directory.
What I want to achieve is getting all relevant JARs (mine and external) is one directory. Very similar to the way you package a WAR with Maven.
(And to clarify - I'm not interested in an assembled "FAT JAR" that contains all the dependencies in a single file. Just one directory with all JARs in it)
Im not 100% sure about the suprobject dependencies but I think SBT native packager should help you do something like that, and will also provide a start-script for windows and unixes:
http://www.scala-sbt.org/sbt-native-packager/GettingStartedApplications/MyFirstProject.html
I would recommend sbt-pack for creating self-contained JARs:
https://github.com/xerial/sbt-pack
I use it and haven't seen a glitch so far.
It also generates both OS X/Linux as well as Windows .bat entry scripts for the main classes/objects you choose.

what exactly maven dependency tag does?

I have started reading and trying maven since yesterday. But its making me go crazy.
I am java developer but never came across ant or maven before.
I want to know what exactly happens with the dependency tag in POM.xml file?
Lets say, I am using camel framework and want to use camel core jars.
If one of my class file contains following line:
CamelContext context = new DefaultCamelContext();
so what exactly I need to do after that?
Do I need to include the jars myself in the class path or dependency tag will download the jar files over internet for me?
If the case is former, what dependency tag will do? & where should I place my jar files? I mean is there any specific location on my hard drive? and
if the case is lateral then during compile time I get error "cannot be resolved to a type"
And the imports are to be specified or not?
I know the question might sound silly but I am not able to find its answer.
I have tried googling alot, it didn't help me still.
Any help would be greatful, even help on maven topics which I might come across in near future would be appreciated.
Thanks in advance.
Solved. Please check https://stackoverflow.com/a/20094312/1121208 for help
dependency tag will download the jar specified in the dependency tag for you if available. Otherwise will raise a pom.xml error - could not found dependency..
Imports have nothing to do with maven. They will appear when you will you another class in your class/java file. So if you import in build path the jar by yourserf or if you put it there with maven, you will have the import.
Are you using eclipse or any other ide ?
First of all, Maven is a build tool. It doesn't run your app. It builds it. So, at runtime, the classpath needs to be set like for any oter application yo would have built with something else.
When you build an app, you depend on external libraries. The dependencies mechanism of Maven simply lets you declare wwhich libraries your ap needs. When you build your app, Maven downloads these libraries from a central repository (or sevaral ones), and stores them in a local repository on your hard drive. These jars are automatically added to the build classpath by Maven. At runtime though, depending on the kind of ap you're building, you'll have to copy or embed those jars in order to create a runnable application.
The rules of Java don't change just you build them with Maven. Meven uses the stadard Java compiler (javac). And of course, if you want to use a class by its simple name, you'll have to add an import statement for this class.
I think that, before using Maven, you should try to compile and run a simple application depending on an external library without using any IDE. You would then understand better all the steps that are required to build and run an app, the concept of build and runtime classpath, etc.
Finally got what I needed to know
Sharing it for others who may stuck up in same situation
Does dependency tag download the jar specified?
maven dependency tag actually downloads the jar files you specify in the dependency tag. It downloads and save it under .m2/repositories(local repository) folder on your hard drive (along with some information like last updated, etc)
Local repository is shared among all your projects
from where it downloads?
It downloads the jar from the central repositories. There central repositories contain almost all the open source jar files one needs in a project. It downloads based on information you provide in groupid, artifactid, etc.
http://repo1.maven.org/maven/
http://mvnrepository.com/
can be checked for correct groupid, etc
Once these jar files are downloaded, they are automatically added to the classpath and are available in your project for use.
If the jar files you are searching for, are not available in the central repository, maven may throw error, in that case you can download it manually and let maven know about it.
Without maven you need to put jars into lib folder.
With maven you specify as declaration inside <dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
and when you do mvn package, maven will download required jars on your PC.
With Eclipse and m2e (maven eclipse integration) you can do that all not leaving Eclipse,
and even get sources for used libraries automatically.
Read http://maven.apache.org/ It worth it.

How to mavenize a standard eclipse project but only for some dependencies

I have an existing eclipse project with standard dependencies in the classpath. I need to add a new dependency through maven but the rest of the dependencies need to stay there as jars bundled with the project.
I am using m2e, if I right click on the project --> maven --> enable maven, a pom file is created. At this stage I can add my new dependency through the pom file but all the existing dependencies seem to be gone from the classpath.
Hence the question: Is there a way to create a hybrid project that has both standard dependencies and maven dependencies?
You could add your legacy dependencies by using the scope "system" (and the tag "systemPath") ?
See http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html.
I don't think you should even attempt to create such a thing, and I don't know why you would want to.
If you want to use Maven, then you should define all your dependencies in your pom so that a maven build will actually work. If all your dependencies aren't defined, how do you expect maven to build your project?
You need to decide which means of dependency resolution you want to use instead of trying to mix two together.

Local Project Dependencies and Maven

I'm converting an ant backed Netbeans project into an Maven project. I've got most of the third party libraries set up in the POM, however now I've run into problems with setting up the local dependencies.
With the previous Netbeans way of doing things, it just added a project reference [with links to the source and jar location, rebuilt the dependency if the depedency's source had been changed and hadn't been compiled]. However I'm not sure how to setup up Maven to emulate this behavior. Is it possible?
Example:
Projects/SharedLibrariesResource [Ant based project]
Projects/WebSite [this is a maven based project]
Projects/Client
In this example the website and client projects don't connect to each other, but they do share the SharedLibrariesResource. Website should compile to produce a War with links to the SharedLibrariesResource
The way I understand the question, the Website maven project depends on the ant SharedLibrariesResource project. When Website is built, it should include the SharedLibrariesResource artifacts. The assumption is SharedLibrariesResources produces a jar artifact.
One way to achieve this is to
install SharedLibrariesResource to your local maven repository each time ant builds it
specify this as a dependency in Website pom.
We can use maven ant tasks to achieve the first.