【问题标题】:META-INF (Is a directory) on extracting jar提取jar时的META-INF(是一个目录)
【发布时间】:2015-12-19 15:17:29
【问题描述】:

我用 Maven [1] 创建了一个 jar 文件,最后它创建了一个名为 medusa-java-jar-with-dependencies.jar 的 jar 文件。当我尝试提取文件的内容时,我收到此错误 [2]。为什么我会收到此错误?这是pom.xml 的问题吗?

[1] Maven 配置

 <plugin>
            <!-- create one fat jar -->
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass></mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>
                        jar-with-dependencies
                    </descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>${maven.jar.version}</version>
            <configuration>
                <excludes>
                    <exclude>**/log4j.properties</exclude>
                    <exclude>src/main/java/org/apache/hadoop/mapred/examples/Teste.java</exclude>
                </excludes>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>org.apache.hadoop.mapred.examples.ExampleDriver</mainClass>
                        <classpathPrefix>dependency-jars/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

[2]解压jar文件时出错

$ jar xf medusa-java-jar-with-dependencies.jar 
java.io.FileNotFoundException: META-INF (Is a directory)
   at java.io.FileOutputStream.open0(Native Method)
   at java.io.FileOutputStream.open(FileOutputStream.java:270)
   at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
   at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
   at sun.tools.jar.Main.copy(Main.java:909)
   at sun.tools.jar.Main.extractFile(Main.java:1069)
   at sun.tools.jar.Main.extract(Main.java:981)
   at sun.tools.jar.Main.run(Main.java:311)
   at sun.tools.jar.Main.main(Main.java:1288)

【问题讨论】:

  • META-INF 目录可能是 .jar 文件中的第一个条目,因此 FileNotFoundException 可能是您无权在当前目录中创建目录的误称。跨度>
  • 你使用哪个版本的 maven-assembly-plugin?
  • 我使用的是 Apache Maven 3.0.5。这是你要求的吗?
  • 并且组装插件的版本是2.5.5
  • 也许我应该使用 One-Jar 插件而不是 maven 程序集。

标签: java maven jar


【解决方案1】:

我找到了解决方案。由于我想使用 MapReduce,我不应该构建一个包含所有依赖项的胖 jar,但我应该将这些 jar 放在 $HADOOP_MAPREDUCE libs 目录中。我做到了,而且成功了。

这个link 帮助了我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 2018-07-23
    相关资源
    最近更新 更多