I have a maven-managed project with some modules.
One module contains some native codes inside "src/main/resources/native" directory.
Second module packages all related modules to a WAR file.
Here comes the question : How to copy the "native/" directory (and its sub-directories) in first module to WEB-INF/native directory in the second module ?
I found a copy resources plugin , but it seems not what I want. (It copies directory inside the same module , but I want cross-module copy)
This is doable with dependency:unpack (that I would bind on the prepare-package phase) and the appropriate excludes/includes . See the Unpacking specific artifacts example.
The goal of modules in maven is to spearate them from each other. I am afraid there will be no satisfactory solution inside maven as this goes against the grain.
A solution could be to create a war archive with your resources and depend on that to build your final war.
I use for a project for example the camel-web resources by adding a dependency :
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web</artifactId>
<version>${camel.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
The war resources are merged with my web resources.
Related
I have an EAR with the following structure
myWar1.war
WEB-INF/lib/myJar.jar
myWar2.war
I want myWar2.war to be able to load myJar.jar.
In JBoss 7/EAP 6.x you can add a dependency like this in jboss-deployment-structure.xml
<sub-deployment name="myWar2.war">
<dependencies>
<module name="deployment.myEar.ear.myWar1.war" />
</dependencies>
</sub-deployment>
I don't know of a WAS equivalent. I have tried adding a class path entry in myWar2.war's manifest file but WAS seems to ignore it.
If I have a manifest entry such as
Class-Path: myWar1.war/WEB-INF myWar1.war/WEB-INF/lib myWar1.war/WEB-INF/lib/myJar.jar
myWar1.war/WEB-INF and myWar1.war/WEB-INF/lib are added to the module class path but myWar1.war/WEB-INF/lib/myJar.jar is not
I know I can turn the jar into a utility jar at the EAR root level but would prefer not to. It's an established application (the second war is new) I don't want to mess around with it too much. If I can solve the dependency with a class path entry that would be ideal.
This is not possible. JARs in WEB-INF/lib are considered to be local classpaths to myWar1.war, and you can't reference JARs from another WAR. Your only option is to move the JAR to the EAR (either the lib/ directory, or to another directory and add Class-Path to the META-INF/MANIFEST.MF of both WARs).
I am facing a problem modifying dependencies within Intellij12.04.
Under my project folder, I have two modules, the second of which depends on the first:
a.b.c.somebusiness
---> a.b.c.tests
I want to remove one dependency from a.b.c.tests and add it into a.b.c.somebusiness module, but I don't want to create a circular dependency tree. When I try to remove the dependency from the a.b.c.tests module and add it into the a.b.c.somebusiness module, I am getting the following error:
"Source root "C:\Perforce\depot\Projest\Main\a.b.c.tests\src\test" cannot be defined in module "Main" because it belongs to content of nested module "a.b.c.tests""
I don't know what to do to resolve this issue. Can anyone suggest an approach that would fix the error I'm receiving?
You should look at using apache maven and the project object model (pom.xml file)
When you define your dependencies under <dependencies> in the pom.xml, they are managed automatically by IntelliJ. So you will never have such problems from moving dependencies into file folders manually.
If you configure it similar to the fashion shown below, your dependencies will work automagically.
<dependencies>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>a-b-c-tests</artifactId>
</dependency>
<dependency>
<groupId>some.other.org</groupId>
<artifactId>some.other.dep</artifactId>
</dependency>
</dependencies>
How to get started: install apache maven and add a pom.xml at the root of your project. Right click it to add in as a maven file in IntelliJ.
Good luck!
The best approach to isolate issue faced is to use Apache Maven. It gives following advantages and will be easy for you to manage dependencies in a cleaner and efficient way. Hope this will help a new comer.
The task of downloading Jar files and other dependencies is done automatically.
In Maven, it’s easy to add new dependencies by writing the dependency code in the pom.xml file.
Makes it easy for the developer to build a project in different environments without worrying about the dependencies, processes, etc.
Having said that, please follow these steps to fix the issue.
Go to InteliJ IDEA
Right click the Project and Click Add Framework Support and check
the "Maven" option This will create pom.xml file for the project
Double click the pom.xml file and include dependencies as needed.
(The dependencies could be found by searching via
https://mvnrepository.com/)
When the dependencies are added it will automatically download, if
does not, right click the project and select "Maven" and click
"Reimport".
Now you are project is added with the dependencies you have
specified.
Once above is completed, try to build the project in order to deploy/run.
Go to Run -> Edit Configuration -> Add New Configuration -> Select
Maven -> Fill the name etc. -> Type 'clean install' in the 'Command
Line' field and press OK.
Now you can run the Maven in the Run/Debug Configurations
The output can be seen in the target folder of your project
directory.
Check this out for more information - Official Page for Apache Maven:
https://maven.apache.org/index.html
I am trying to build an RPM from my Maven project. I have 5 different modules and each one has its own pom.xml, In the root I have one pom.xml which builds all modules (Typical Maven Setup). When I build an RPM, I want to include a directory that is not part of the maven directories. Its above a directory [from the root folder that contains my maven modules]. What is the best way to include that in my RPM? or rather what is the best way to refer to a directory with out hardcoding the path? I am confused about ${baseDir} and what it refers to?
Thank you.
${project.basedir} refers to the root of the project, ie where the pom.xml is, so you could use that in <systemPath>${project.baseDir}/../../dirYouWant</systemPath>
In general though, Maven best-practices would frown about relying on the relative paths around your projects from being there. Instead, I suggest deploying those files as there own project to your maven repository (as a zip, jar, whatever), and then getting them as part of your rpm build. Depending on what plugin you are using to build your RPM, you can unpack those files automatically.
Try this
<dependency>
...groupid,artifactid etc..
<scope>system</scope>
<systemPath>path/to/your/jar</systemPath>
</dependency>
Did you mean you want to add another project to your maven build being level above?
you can do it like this :
in your parent pom :
<modules>
<module>../projectdirectory</module>
</modules>
in your projectdirectory pom :
<parent>
<groupId>...</groupId>
<artifactId>...parent...</artifactId>
<version>...</version>
<relativePath>../parentProject/pom.xml</relativePath>
</parent>
I need to configure the jars in my pom.xml file in my web application in such a way that I need not use the lib folder to store all the jar files.
Please help.
If you really have dependencies which are stored in a lib folder (I assume those jar's don't exist in Central) you can use the system dependency
<dependency>
<groupId>...</groupId>
<artifactId>..</artifactId>
<scope>system</scope>
<systemPath>PathOnYourSystem</systemPath>
</dependency>
But i assume you mean something different, cause the above will procuce a warning on Maven 3. If you have a dependency which is provided by the Container (for example Tocmat) you can define a dependency as provided.
But the best is to put such dependencies into a local repository manager which i hope you are using (Artifactory, Nexus, Archiva).
You can mannually add them to your local repository (since it seems that they are not at central).
But the best would be to set up your own (or company) repository to hold them for you.
I need to download a file from a non-standard layout repository.
The standard repository layout is groupId>/<artifactId>/<version>/<artifactId>-<version>.<packaging> however, I need to download the following file:
http://hudson.myserver.com:10000/repo/ocp-services/schemas/trunk/201/archive/schemas/dist/schemas.jar
where ocp-services is effectively the groupId, schemas is the artifactId and 201 is the version.
How would I add a dependency to this file and get it downloaded into my project and local repository?
This is a Hudson file repository if this is of any help, but it is a third parties so difficult to get them to change any location.
One option would be to register a custom ArtifactRepositoryLayout implementation and to declare a repository using this custom layout. I've never done that but it should be possible, check this blog post.
A second option would be to configure Maven to go through some kind of custom proxy (e.g. a Servlet) and to rewrite the URL on the fly for this particular dependency.
In both cases, I'm afraid Maven will complain about missing metadata ("A dependency in Maven isn't just a JAR file", see 3.5.5. Maven's Dependency Management) because the hudson file repository is just not a Maven repository. Maybe this can be handled programmatically though. But as I said, I've never done this.
A third option would be to ask the project building the JAR you need to deploy it (in the maven sense). That would be of course the best solution.
A last one option would be to just download this JAR and to install it manually in your local repository. If this is an option, go for it.
Have you tried adding this to your pom.xml :
<dependencies>
<dependency>
<groupId>ocp-services</groupId>
<artifactId>schemas</artifactId>
<version>201</version>
<type>jar</type>
</dependency>
</dependencies>
or if that don't work as Pascal says install it manually