问题
I'm working on my first Maven project which will ultimately package a Java app in a Debian package (using the jdeb plugin). I'm trying to use the assembly plugin to build a tar file, but it looks like the generated file does not always include directory entries, which will cause dpkg install to fail.
Has anyone seen this before?
Specifically, the generated tar file does not include directory entries for:
- a fileSet that specifies
<includes>
(leaving<includes>
will result in a directory entry int he tar file) - a dependencySet
Here's an assembly file that doesn't use the <includes>
<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>simple</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
</moduleSets>
<fileSets>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/etc/${project.artifactId}</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/usr/lib/${project.artifactId}/lib</outputDirectory>
<scope>runtime</scope>
<useProjectArtifact>true</useProjectArtifact>
</dependencySet>
</dependencySets>
<repositories>
</repositories>
<componentDescriptors />
</assembly>
Here are the contents of the tar file:
tar tvf assembly-test-0.0.1-SNAPSHOT-simple.tar
drwxr-xr-x 0/0 0 2012-04-10 12:54 etc/assembly-test/
-rw-r--r-- 0/0 0 2012-04-10 12:52 etc/assembly-test/file1.xml
-rw-r--r-- 0/0 0 2012-04-10 12:52 etc/assembly-test/file2.xml
-rw-r--r-- 0/0 2131 2012-04-10 13:26 usr/lib/assembly-test/lib/assembly-test-0.0.1-SNAPSHOT.jar
Now if I use an assembly with some include patterns:
<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>include-match</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
</moduleSets>
<fileSets>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/etc/${project.artifactId}</outputDirectory>
<includes>
<include>*.xml</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/usr/lib/${project.artifactId}/lib</outputDirectory>
<scope>runtime</scope>
<useProjectArtifact>true</useProjectArtifact>
</dependencySet>
</dependencySets>
<repositories>
</repositories>
<componentDescriptors />
</assembly>
The contents of the tar file loses the directory entry:
tar tvf assembly-test-0.0.1-SNAPSHOT-include-match.tar
-rw-r--r-- 0/0 0 2012-04-10 12:52 etc/assembly-test/file1.xml
-rw-r--r-- 0/0 0 2012-04-10 12:52 etc/assembly-test/file2.xml
-rw-r--r-- 0/0 2131 2012-04-10 13:26 usr/lib/assembly-test/lib/assembly-test-0.0.1-SNAPSHOT.jar
This seems like a bug in the assembly plugin, though I'm still experimenting with it. I can certainly work around it (use a preinst script in the package, maybe build out a directory structure for jdeb to build from), but I'd love to keep as much as possible in the descriptor file.
回答1:
Think I can answer this with a method that can force creation of directory entries in the tar files (I actually found this elsewhere, but don't remember where) - add a fileSet while excluding all contents, such as:
<!-- force entry for /usr/lib/${project.artifactId} -->
<fileSet>
<directory></directory>
<outputDirectory>/usr/lib/${project.artifactId}</outputDirectory>
<excludes>
<exclude>*/**</exclude>
</excludes>
</fileSet>
Not elegant, and gets verbose if you have lots of directories, but it works. However for my specific case of creating a debian package, I ended up using the Assembly plugin to build a "directory" format assembly instead, and then had the jdeb plugin use the directory structure (and set the filemodes), which ended up a bit simpler overall.
回答2:
There's a simple way to work around this, simply include the directories you want or "**/" if you want all of them, so for example:
<include>mydir/**/</include>
Note the trailing / as that's the thing that pulls in the directory. I think the current behaviour is probably intentional, since include appears to pull in precisely what you include and nothing else. As an aside though the resulting tarball does not satisfy npm, so maven's support still seems a little suspect.
来源:https://stackoverflow.com/questions/10097170/maven-assembly-plugin-not-creating-tar-files-with-directory-entries