I have existing two maven projects, I want to combine them after build into one project.
I have not created these projects module wise, the two projects are separate maven projects.
Below is the POM xml code part from existing projects.
Project One pom.xml
<groupId>com.olex</groupId>
<artifactId>olex-reg</artifactId>
<version>1.0</version>
<packaging>war</packaging>
Project Two pom.xml
<groupId>com.olex</groupId>
<artifactId>olex-qba</artifactId>
<version>1.0</version>
<packaging>war</packaging>
Combine Project pom.xml
<groupId>com.olex</groupId>
<artifactId>olex-war</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
I want to combine these projects into one like olex-war, A complete project.
After build I want all the code to be copied to this olex-war project.
Please suggest / provide hint if anyone aware of such scenario.
Thanks in advance.
You could start with a pom like this, that extract all the content of your old war files into content directory. Then you could package everything in that directory (except for web.xml and other metadata) in your new war.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olex</groupId>
<artifactId>olex-war</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>olex-war Maven Webapp</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>olex-war</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>unpack</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.olex</groupId>
<artifactId>olex-qba</artifactId>
<version>${project.version}</version>
<packaging>war</packaging>
</artifactItem>
<artifactItem>
<groupId>com.olex</groupId>
<artifactId>olex-reg</artifactId>
<version>${project.version}</version>
<packaging>war</packaging>
</artifactItem>
</artifactItems>
<excludes>WEB-INF/web.xml</excludes>
<includes>**/*.class, **/*.jar, **/*.properties</includes>
<outputDirectory>${project.build.directory}/content</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
You should combine your projects manually. Many elements (like config files) need manual merging anyway and you want to avoid to accidentally loose something from one project because the other overwrites it quietly.
This would be a horrible mind-dulling task if there were not Version Control Systems to help you with the merging.
First set up a version control system (VCS). It will help in many other situations as well. I recommend git, but if you have another already up and running that should do it just fine, I won't use any fancy specials here.
Then create an empty folder for the new project and copy all the data from the first project into it. Do all replacements as you see fit (web.xml, pom.xml, other config files) and commit it to the VCS.
This will write this version of all files into the VCS and you cannot loose them again, so if you happen to make a mistake, no worries, just revert all changes back to this point.
Then copy the content of the second project over it overwriting everything thats duplicate.
Now you can use the "show differences" feature of your VCS to see what you'll need to merge. Most likely you can do so in a graphic tool so that makes it easy.
Most of them will be "unknown" that is, the new file does not exist in the VCS, yet. Most likely you can just add them to the VCS and be done with them.
More interesting are the ones that are "modified". That means the file already existed and the other project contained them as well. You will have to merge them into a combined version that is from now on valid for your new project.
When you are done you should have all the files (including pom.xml) necessary for the new project ready. Commit them to the VCS to not loose this state in the future.
Related
We have a couple of legacy Java projects, which we converted to Maven projects / modules. Previously, all projects were NetBeans projects and had no real dependency management. External dependencies existed on the companies network drive and were directly included as JARs in the NetBeans projects of each module. For the internal dependencies, simple project references were used. It was a pain to build everything because the programmer had to build everything in the right order.
Now, we are in the position that we can open all the Maven modules in IntelliJ IDEA and NetBeans. However, I am having trouble figuring out the best way to combine the different modules and external dependencies in a specific way, which conforms to in-house plugin-like structure. Especially with NetBeans (developing with both IDEs must be possible).
Here is how the git repositories / project structure roughly looks like. The folder structure of the modules is the default Maven structure for each module. The list feature of this site was too clumsy, so I included it as screenshot...
We have an internal maven repository for the stuff and building with maven etc. is working. For Intellij IDEA i can run and debug the end product for customer1 via a custom run configuration, which copies the needed files in the needed structure:
With IntelliJ IDEA, I can debug the software, but I think that the approach (custom IntelliJ run config I created, pointing to all needed JARs and files directly) is rather ugly, and for NetBeans I could not find a similar "run configuration" mechanism.
So I tried to achieve this build process by creating a new "Customer1Runnable" Maven project as a sort of build description, which points to all needed Maven modules. Based on this, I believed I could achieve and automatism to create the needed software structure. Ergo copy all modules into a plugin folder and all dependencies of the modules into a lib folder inside the Customer1Runnable project, using the maven-assembly-plugin.
First off, is my assumption correct that this is a possible use case for the maven-assembly-plugin?
The project itself does not have any source files, it is only a pom.xml and the assembly-config.xml descriptor. I attached the assembly-plugin to the package phase. When running the mvn package command all connected modules are built, but for the execution of the assembly-plugin I get the following output:
For starters, I only tried to include one module in the assembly descriptor. This is the XML (opicom-assembly.xml) for it:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>opicom-assembly</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>my.company.reporting:module1</include>
</includes>
</moduleSet>
</moduleSets>
</assembly>
pom.xml of Customer1Runnable project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>1.6</version>
<groupId>my.company.customer1</groupId>
<artifactId>OpicomRunnable</artifactId>
<packaging>pom</packaging>
<name>OpicomRunnable</name>
<repositories>
<repository>
<id>Company-Maven-Repo</id>
<url>file:\\\\MyCompany\TFSDrop\MavenRepo</url>
</repository>
</repositories>
<modules>
<module>../my.company.customer1.module1</module>
<module>../my.company.customer1.module2</module>
.
.
.
<module>../../MyCompany_Common/Report/my.company.reporting.module1</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>opicom-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
The pom of a module looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.company</groupId>
<artifactId>reporting</artifactId>
<version>1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>module1</artifactId>
<version>1.3</version>
<packaging>jar</packaging>
<dependencies>
<!-- external dependencies -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<finalName>my-company-${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>../build</outputDirectory>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Thanks for any input on what I am doing wrong here / how to achieve this with Maven.
EDIT:
As requested, here an example project as ZIP-File.
https://drive.google.com/drive/folders/1ilJeTrOPgYgUTdOP0J4BQcBnPT5fls0k?usp=sharing
The parent directories ModuleGroupCustomer and ModuleGroupCommon do represent git repositories in the real scenario. The relative module path is caused, because the maven project which should be my "run config" points to maven projects in both repositories.
Maybe I am misunderstanding Maven in general? I thought of it in terms of use cases for dependency management similar to .Net nuget packages, but also as "project configuration" like ordinary NetBeans/Intellij projects.
Is it better to simply stick to the existing NetBeans projects for day to day development?
After a long and tedious process of trial and error, I have found a solution which is working for me. So I decided to share the solution online, in case someone else runs into a similar problem. Here is a link to the final zip archive containing working example projects => File CustomerRunnable_RunningAssemblyPluginStackoverflowExample.zip https://drive.google.com/drive/u/0/folders/1ilJeTrOPgYgUTdOP0J4BQcBnPT5fls0k
My error was that I misunderstood how the assembly-plugin works. The approach that I executed the plugin inside my aggregator pom (CustommerRunnable) is wrong, as this maven project only exists as parent pom.
The CustommerRunnable pom.xml references all customer plugins as modules. Those modules have not the CustommerRunnable as parent, but a different pom. Then I created a separate maven project "distribution". The pom.xml of the distribution defines all the plugins (needed customer maven modules) as dependencies. It also has the CustommerRunnable pom.xml as parent. Hence when I run the project in NetBeans, all connected modules are also build(if necessary).
It also configures the assembly plugin. The assembly plugin is attached to the maven package-phase and thus executed with it. It also uses a custom assembly descriptor, which copies all the previously defined plugins into the right folders. This is done by using dependencySets with include and exclude patterns.
See https://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html for details on this.
So one dependencySet copies all jar files of all plugins to a /plugin folder by using an include pattern. Then this approach is inversed to copy the jar files of all external dependencies to a /lib folder.
The descriptor also defines some extra files to copy to a particular location. exec-maven-plugin, so I can comfortably start the customer software out of NetBeans. I didn't yet manage to configure the execute plugin correctly regarding the needed classpath arguments.
Endresult looks like this:
It is also worth noting that the configurations of the "Build project", "Run project" and "Debug project" inside NetBeans need a tiny bit of modification. (Right Click Module "distribution" -> "Properties" -> point "Actions"
I'm trying to have multiple package hierarchies in multiple locations in a Java project. To explain further: our own software is in the packages com.company.V2.*. I now want to add these external repositories:
org.freedesktop.dbus
org.freedesktop.NetworkManager
but unlike in previous versions of Netbeans, it seems there is no way to specify multiple directories for these separate packages. Under Project Properties, Sources, there is one setting Source Folder, which is where the com.company.V2.* hierarchy is. There is no way to say 'for com.company look in /dir1/dir2; for org.freedesktop.dbus look in /dir4/dirZ etc.' Obviously Netbeans can do this, because classes in the java.lang.* hierarchy are found, for example.
There are two consequences:
Maven cannot find the source when I build.
Netbeans cannot find the source when I control-click and shows multiple errors in the editor windows relating to methods having wrong parameters etc.
I've checked-out the two external repositories into the project root. I fixed the Maven problem by adding this to the POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>dbus-java/dbus-java/src/main/java</source>
<source>kk-dbus-nm-java/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
but this doesn't fix the editor window errors. It doesn't even fix the Maven problem properly because it is necessary to clean-and-rebuild (shift-F11) after each source change; otherwise I get a run-time error, which indicates to me that Maven isn't always finding stuff in the same place:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: org.freedesktop.dbus.connections.impl.DBusConnection.addSigHandler
at com.company.V2.net.Wifi.openBusConnection(Wifi.java:38)
at com.company.V2.net.Wifi.<clinit>(Wifi.java:23)
One way of fixing all this would be to use symlinks so that Maven and Netbeans see all packages in one hierarchy, but regrettably we have to support developers on Windoze / NTFS and in typical MS fashion, the simple matter of symlinking becomes ridiculously complicated under Windoze. I have created the symlinks and they solve all the problems given above, but I would prefer a 'proper' solution and not one involving a hacky workaround.
For the sake of anyone else looking, here is the best I have so far.
My project really only depends directly on org.freedesktop.NetworkManager, which in turn depends on org.freedesktop.dbus. So in my project pom.xml I have:
<repositories>
<repository>
<id>kk-dbus-nm-java</id>
<name>NetworkManager</name>
<url>file:///home/myself/projects/kk-dbus-nm-java</url>
</repository>
</repositories>
and
<dependency>
<groupId>kkdev.dbus</groupId>
<artifactId>org.freedesktop</artifactId>
<version>1.0-KKDev</version>
</dependency>
then /home/myself/projects/kk-dbus-nm-java/pom.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kkdev.dbus</groupId>
<artifactId>org.freedesktop</artifactId>
<version>1.0-KKDev</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.github.hypfvieh</groupId>
<artifactId>dbus-java</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
This question already has answers here:
Maven: add a dependency to a jar by relative path
(10 answers)
Closed 6 years ago.
Currently I'm having the problem that I have an Java project which was created with eclipse and which should now be builded with maven. I haven't created this project I just need to migrate it. The problem here is that I have a bunch of 3rd party jar's which need to be included to properly build the project. I know nothing about these jars (and I actually don't care what they do and where the came from).
I managed to find resources on how to add these jar's via command line to ma local repro and I further created a pom.xml which does the job for me (so I don#t need to use the command line) but somehow its not working properly. I doen't matter if I use the command line or the pom.xmo, non of the two approaches works for me. When i run the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>common</groupId>
<artifactId>common.master</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>common</groupId>
<artifactId>org.proj4j</artifactId>
<name>org.proj4j</name>
<version>0.1.0</version>
<packaging>jar</packaging>
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>install1</id>
<phase>package</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>proj4j-0.1.0.jar</file>
<groupId>common</groupId>
<artifactId>org.proj4j</artifactId>
<name>proj4j</name>
<version>0.1.0</version>
<packaging>jar</packaging>
</configuration>
</execution>
<execution>
<id>install2</id>
<phase>package</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>proj4j-support-0.1.0.jar</file>
<groupId>common</groupId>
<artifactId>org.proj4j</artifactId>
<name>proj4j-support</name>
<version>0.1.0</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
the jars are put into my local repro under the specified group id, artifact ID etc. But the compiler still fails with an Unknown Symbol Error which says that the required class could not be found during compilation. I guess the reason are the artifact ID and the group ID because I came up with them. They are not related to my 3rd party jars at all. But I also don't know the proper group ID / artifact ID's because i know nothing about the jars. They are also partially self written by colleges.
What can I do to make maven find the required libs and to resolve all missing classes. Like I already said, with eclipse everything runs fine and without any problems. Shouldn't it be possible put the jar somehow into one folder in my local repro and tell the compiler If you search for anything start looking here ?
See if one of the below works for you:
How to add local jar files in maven project?
Maven: add a dependency to a jar by relative path let me know if it helps
They explain in details what needs to be done..
You can put your jar manually in your repo. You dont must know nothing about this jars, the artifact-id and the group-id affect the route in the repo and the name of the dependencie that compiler will look for.
I recommend you add some dependencie that exists in maven repo and observe the route and name of file that the pom creates in your local repo, after that sure you look the way that pom.xml works.
I'm doing project with JBehave and want my reports to be pretty. Here I've read that I can use the unpack-view-resources goal. The problem is following: I use IntelliJ Idea and I used File->Project Structure->Libraries to add the project From Maven. So, I have .jar files but don't have access to pol.xml (I don't see this file at all).
Where I should create it? Or how I have to setup JBehave to have an ability to use pol.xml for view resources unpacking?
Maybe there is another solution for this problem, or download all .css and .js files by myself is the only way in my case?
SOLUTION:
I only had to right mouse click on the project name (the root folder) and choose "Add Framework Support...". Than I have a pom.xml file.
I used this example, so it looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>3.8</version>
<classifier>resources</classifier>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.jbehave.site</groupId>
<artifactId>jbehave-site-resources</artifactId>
<version>3.1.1</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>3.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>3.8</version>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Than I use Maven panel (on the right of the IntelliJ window, as Engineer Dollery said) called "Maven Projects" and see there my project. I expand it, there I see Lifecycle and expand it too, than I choose "install" and click "run" (green arrow on the top of the panel) and I have all needed files unpacked.
First, You shouldn't be adding libraries to the project manually -- that's what maven is for, so start by deleting the one's you've added. The maven panel, usually on the right of the intellij window should have a tree that can expand to show Lifecycle and Plugins -- it is here that you should find the maven goal you describe. If not, you can run any maven goal through editing run configurations from the toolbar, adding a new maven run config and stating your goals there.
Good luck and let us know how it goes.
This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
SpringSource.org changed their site to http://spring.io
Does someone know how to get the latest build without Maven/github? from http://spring.io/projects
Please edit to keep this list of mirrors current
I found this maven repo where you could download from directly a zip file containing all the jars you need.
https://maven.springframework.org/release/org/springframework/spring/
https://repo.spring.io/release/org/springframework/spring/
Alternate solution: Maven
The solution I prefer is using Maven, it is easy and you don't have to download each jar alone. You can do it with the following steps:
Create an empty folder anywhere with any name you prefer, for example spring-source
Create a new file named pom.xml
Copy the xml below into this file
Open the spring-source folder in your console
Run mvn install
After download finished, you'll find spring jars in /spring-source/target/dependencies
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spring-source-download</groupId>
<artifactId>SpringDependencies</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>download-dependencies</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Also, if you need to download any other spring project, just copy the dependency configuration from its corresponding web page.
For example, if you want to download Spring Web Flow jars, go to its web page, and add its dependency configuration to the pom.xml dependencies, then run mvn install again.
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>