Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Intellij可执行Jar-无主清单属性Vs无法找到或加载主类_Java_Maven_Intellij Idea_Jar - Fatal编程技术网

Java Intellij可执行Jar-无主清单属性Vs无法找到或加载主类

Java Intellij可执行Jar-无主清单属性Vs无法找到或加载主类,java,maven,intellij-idea,jar,Java,Maven,Intellij Idea,Jar,我正在使用intellij idea开发一个小型Java应用程序。有一个包和一个类。在jar格式之外时,该类按预期运行 我可以构建一个jar,并将所有依赖项部署到同一个目录,jar可以按预期工作(在配置jar构建过程时,我使用复制到输出路径和通过清单链接选项来实现这一点)。然而,当我试图构建一个包含所有依赖项的胖jar文件时,根据META-INF/MANIFEST.MF的位置,我会遇到两个错误之一:没有主清单属性,无法找到或加载主类 考虑到如果所有依赖项都与所述jar文件位于同一目录中,我可以得

我正在使用intellij idea开发一个小型Java应用程序。有一个包和一个类。在jar格式之外时,该类按预期运行

我可以构建一个jar,并将所有依赖项部署到同一个目录,jar可以按预期工作(在配置jar构建过程时,我使用复制到输出路径和通过清单链接选项来实现这一点)。然而,当我试图构建一个包含所有依赖项的胖jar文件时,根据
META-INF/MANIFEST.MF
的位置,我会遇到两个错误之一:没有主清单属性无法找到或加载主类

考虑到如果所有依赖项都与所述jar文件位于同一目录中,我可以得到一个工作的jar文件,我假设问题在于类路径

META-INF/MANIFEST.MF
内容如下:

Manifest-Version: 1.0
Main-Class: myPackage.myClass
Class-Path: . myClassJarName.jar
当jar生成时,我会在结构的根目录下看到包含正确信息的
META-INF/MANIFEST.MF

jar的根目录中还有与清单文件相对应的
myPackage/myClass.class

我也可以看到jar文件中的所有依赖项

我的项目结构如下所示-请注意,我添加了两个我尝试过的清单lcoations,以及每个清单lcoations的错误:

 .idea 
 out   
   artifacts
     myPackage_jar
       myPackage.jar
 src
   main
     java
       myPackage
         myClass.java
     META-INF <-------------------- *If here, Error: Could not find or load main class err*
       MANIFEST.MF
   META-INF < ------------------ *If here no main manifest attribute err*
     MANIFEST.MF

   test
     java
       myPackage
         myClass.java
 target
   classes
     myPackage
       myClass
   generated-sources
   generated-test-sources
   test-classes
 mypackage.iml
 pom.xml
.idea
出来
人工制品
我的包装盒
myPackage.jar
src
主要的
JAVA
我的包裹
myClass.java
META-INF

问题是我使用IntelliJ Idea构建过程来构建一个胖罐子,而IntelliJ Idea中没有

为了让它工作,我更新了pom文件:

<?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>myPackage</groupId>
    <artifactId>myClass</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>myClass</name>

    <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>

    <repositories>
        <repository>
            <id>hortonworks</id>
            <name>hortonworks</name>
            <url>https://repo.hortonworks.com/content/repositories/releases/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.3.2.6.2.0-205</version>
        </dependency>
        <dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>1.2.1000.2.6.2.69-1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>myPackage.myClass</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>
        </plugins>
    </build>
</project>

4.0.0
我的包裹
我的班级
1.0-快照
我的班级
UTF-8
1.8
1.8
钟表厂
钟表厂
https://repo.hortonworks.com/content/repositories/releases/
朱尼特
朱尼特
4.11
测试
org.apache.hadoop
hadoop通用
2.7.3.2.6.2.0-205
org.apache.hive
蜂巢执行器
1.2.1000.2.6.2.69-1
maven汇编插件
myPackage.myClass
带有依赖项的jar
组装
包裹
单一的
然后我必须打开Maven窗口(查看->工具窗口->Maven),使用Maven任务
clean
然后
compile
然后
package
,JAR按预期创建

注:

  • 在我的工作结构中,MANIFEST.MF位于
    src/main/resources/META-INF/MANIFEST.MF
  • 我没有使用任何IntelliJ项目结构工件操作来获取工作的胖罐子。即使您创建了一个Maven项目,它们也没有使用Maven
感谢y.bedrov在帮助我理解为什么它不起作用时给出了明确的答案。

不支持胖罐子:。请尝试使用Maven来构建它:
<?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>myPackage</groupId>
    <artifactId>myClass</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>myClass</name>

    <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>

    <repositories>
        <repository>
            <id>hortonworks</id>
            <name>hortonworks</name>
            <url>https://repo.hortonworks.com/content/repositories/releases/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.3.2.6.2.0-205</version>
        </dependency>
        <dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>1.2.1000.2.6.2.69-1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>myPackage.myClass</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>
        </plugins>
    </build>
</project>