Including unpacked war in the Assembly

I have a project that is building a war (no problem). And this war must be packaged with several shell scripts. Since this war contains property files that vary from site to site, we cannot just install the war as it is, but run the property files in it. This is what shell scripts do.

I would like to pack my war in my congregation, like an unpacked war. I see <unpacked> in the assembly descriptor, but I could not get this to work.

Here is my first bin.xml where I just packed the war as it is. This works great:

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>bin</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.basedir}/src/assembly/scripts</directory> <includes> <include>deploy.sh</include> <include>lock_build.sh</include> <include>description.sh</include> <include>url-encode.pl</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> <fileSet> <directory>${project.build.directory}/${project.artifactId}-${project.version}</directory> <outputDirectory>${project.artifactId}</outputDirectory> </fileSet> </fileSets> </assembly> 

Here is my first attempt to unpack:

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>bin</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.basedir}/src/assembly/scripts</directory> <includes> <include>deploy.sh</include> <include>lock_build.sh</include> <include>description.sh</include> <include>url-encode.pl</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> </fileSets> <moduleSets> <moduleSet> <includes> <include>{$project.groupId}:${project.artifactId}:war</include> </includes> <binaries> <includes> <include>${project.build.directory}-${project.artifactId}-${project.version}.${project.packaging}</include> </includes> <outputDirectory>${project.artifactId}</outputDirectory> <unpack>true</unpack> </binaries> </moduleSet> </moduleSets> </assembly> 

Here is my last attempt to get an unpacked war:

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>bin</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.basedir}/src/assembly/scripts</directory> <includes> <include>deploy.sh</include> <include>lock_build.sh</include> <include>description.sh</include> <include>url-encode.pl</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> </fileSets> <moduleSets> <moduleSet> <binaries> <attachmentClassifier>war</attachmentClassifier> <outputDirectory>${project.artifactId}</outputDirectory> <unpack>true</unpack> <includeDependencies>true</includeDependencies> <dependencySets> <dependencySet/> </dependencySets> </binaries> </moduleSet> </moduleSets> </assembly> 

In each of these last two attempts, I only pack the scripts and the war does not come.

I know that I can use the directory ${project.build.directory}/${project.artifactId}-${project.version} , which contains almost all the files in the war, but it does not contain my MANIFEST.MF entries, which include information linking the war to a specific version of Jenkins and Subversion.

What do I need to do to include an unpacked war in my build?


Another attempt

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>bin</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.basedir}/src/assembly/scripts</directory> <includes> <include>deploy.sh</include> <include>lock_build.sh</include> <include>description.sh</include> <include>url-encode.pl</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>${project.artifactId}</outputDirectory> <unpack>true</unpack> <scope>runtime</scope> </dependencySet> </dependencySets> </assembly> 

When I ran this, I got:

 [INFO] ------------------------------------------------------------------------ [INFO] Building My Project 1.0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-assembly-plugin:2.5.2:single (default-cli) @ myproj --- [INFO] Reading assembly descriptor: src/assembly/bin.xml [WARNING] Cannot include project artifact: \ com.vegicorp:myproj:war:1.0.0; \ it doesn't have an associated file or directory. [INFO] Building zip: ~/workdir/trunk/myproj/target/archive/myproj.zip [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ 

Inside the zip, all the banks in the war are good and unpacked, but not my unpacked war.

+6
source share
1 answer

I know that I should be able to add the unpacked war to my assembly. I see that the parameter is unpack , and I know that it works for other dependencies. However, it seems that I can only access it through <dependencySet> or <moduleSet> . I should be able to specify my project as my own module. I must be doing something wrong.


Spleen ventilation

This is the big thing I hate about Maven: Maven does an excellent job of hiding something good from you because it prevents you from doing something you don't need. I hate it when developers build Ant build.xml files because most developers do not understand how to build, and build.xml becomes an unreadable mess. With Maven, this is not a problem. Just configure your project and Maven will take care of this for you.

But sometimes Maven looks like a black box with a bunch of levers and buttons. You sit there, push and pull levers and buttons, trying to figure out how to get him to do what you want to do. I spend too much time trying to help developers set up their Maven projects. They want to do something completely different, like using hibernation or creating a source from WSDL files, and they have no idea how to get Maven to do what they want.

One developer describes this as a self-driving car that cannot go where you want. You can even see your destination in the window, but you cannot figure out how to manipulate the car so that you can get there.

What I want to do should be easy. I just want to create an assembly, and instead of using the packed war file, I want it to be unpacked.

In Ant, this can be done in one task. In Maven, this is a mysterious process. I think I'm close, I probably miss one small configuration parameter that will make it work, but I have been working on this for many hours.


What i finished doing

I used maven-dependency-plugin to unpack my war. I was not sure if this would work, because I do not want the dependency plugin to load the war, but it seems to understand that when I specify my war, I am talking about the current assembly and nothing is loading. (I don’t even have a war in our Maven repo).

I also had to upgrade Maven from 2.x to 3.x because I need to make sure the maven-dependency-plugin works before the maven-assembly-plugin . Since both are launched during the assembly packaging phase, Maven 2.x cannot guarantee an order that includes plugins.

As soon as I used this plugin, all I had to do was specify the directory where I unpacked the war in my build plugin and was included in my zip.

I still want to know how to use the <unpack> object in the build plugin, instead of using another plugin to unpack my war. If someone tells me how to unpack in the assembly file itself, I mark this as the correct answer.

pom.xml

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>unpack</id> <phase>package</phase> <goals> <goal>unpack</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/unwar/${project.artifactId}</outputDirectory> <artifactItems> <artifactItem> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <type>war</type> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.2</version> <configuration> <finalName>${project.artifactId}</finalName> <appendAssemblyId>false</appendAssemblyId> <outputDirectory>${project.build.directory}/archive</outputDirectory> <descriptors> <descriptor>src/assembly/bin.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> 

bin.xml (My assembly)

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>bin</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.basedir}/src/assembly/scripts</directory> <fileMode>0755</fileMode> <lineEnding>lf</lineEnding> <includes> <include>deploy.sh</include> <include>lock_build.sh</include> <include>description.sh</include> <include>url-encode.pl</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> <fileSet> <directory>${project.build.directory}/unwar</directory> <outputDirectory>/</outputDirectory> </fileSet> </fileSets> </assembly> 

ACTUAL ANSWER

Thanks to the khmarbaise link (see comment below), I copied this project build plugin and it almost worked. Like my attempt, he unpacked all the runtime banners, not just the one I wanted. However, he also unpacked my war.

There were only two differences between the answer to this link and my attempt:

  • They included <useProjectArtifact>true</useProjectArtifact> , and I did not. However, this default value is true . Removing him still allowed him to work.
  • They included / before the directory name in <outputDirectory> . Removing this did not matter.

This meant that now it matches what I previously tried. So why did he work this time.

Turns out I tested assembly changes by simply doing mvn assembly:single . In the end, why is the whole assembly and repackaging when I'm just trying to get the assembly to work. When you run only mvn assembly:single - even if everything is already packaged, you will get this error:

 [WARNING] Cannot include project artifact: \ com.vegicorp:myproj:war:1.0.0; \ it doesn't have an associated file or directory. 

And your war is not unpacked. However, if you put the assembly in the package phase and then run mvn package , everything will work fine.

Then I spent the time trying to just get my war, and not all the run-time things related to it. I used <includes/> for this, but since I have a war, not a bank, I had to include the classifier in my <include> .

Finally, everything works for me. I have this in my assembly:

 <dependencySets> <dependencySet> <outputDirectory>${project.artifactId}</outputDirectory> <unpack>true</unpack> <scope>runtime</scope> <includes> <include>${project.groupId}:${project.artifactId}:*:${project.version}</include> </includes> </dependencySet> </dependencySets> 

And while I run mvn package , it works.

This is better than mine with maven-dependency-plugin . Now all the information related to the assembly is in the assembly XML file.

+2
source

Source: https://habr.com/ru/post/979793/


All Articles