Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.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 jar文件中缺少main属性,MANIFEST.MF文件位于META-INF文件夹中_Java_Executable Jar - Fatal编程技术网

Java jar文件中缺少main属性,MANIFEST.MF文件位于META-INF文件夹中

Java jar文件中缺少main属性,MANIFEST.MF文件位于META-INF文件夹中,java,executable-jar,Java,Executable Jar,我无法从命令提示符下运行maven创建的jar文件。我使用下面的命令来执行我的jar文件 ElasticSearchUtility-1.0.0-SNAPSHOT.jar java -jar ElasticSearchUtility-1.0.0-SNAPSHOT.jar 我收到以下信息: no main manifest attribute, in ElasticSearchUtility-1.0.0-SNAPSHOT.jar 我有以下java文件 Document.java (POJO C

我无法从命令提示符下运行maven创建的jar文件。我使用下面的命令来执行我的jar文件
ElasticSearchUtility-1.0.0-SNAPSHOT.jar

java -jar ElasticSearchUtility-1.0.0-SNAPSHOT.jar
我收到以下信息:

no main manifest attribute, in ElasticSearchUtility-1.0.0-SNAPSHOT.jar
我有以下java文件

Document.java  (POJO Class)
DocumentIndex   (Main Class)
我编译了这个maven项目并生成了
.jar
文件。当我执行这个
.jar
文件时,它没有执行

请找到我的项目结构

更新的
pom.xml

<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>ElasticSearchUtility</groupId>
<artifactId>ElasticSearchUtility</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>rest</artifactId>
        <version>5.1.2</version>
    </dependency>

</dependencies>

<build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                </configuration>
            </plugin>

            <!-- Set a compiler level -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!-- Make this jar executable -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/log4j.properties</exclude>
                    </excludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>ProjectJar.project.App</mainClass>
                            <classpathPrefix>dependency-jars/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <!-- Copy project dependency -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!-- exclude junit, we need runtime dependency only -->
                            <includeScope>runtime</includeScope>
                            <outputDirectory>${project.build.directory}/dependency-
                                jars/</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            </plugins>
    </build>
    </project>

您已经添加了编译器插件,但没有指定哪个类是您的主类。这就是为什么您会得到确切的错误
无主清单属性
,因为编译器找不到它。因为主类是应用程序的入口点,所以无法启动它

要解决此问题,请将DocumentIndex主类添加到pom.xml内部的配置中。在maven编译器插件的配置标记内添加:

    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <classpathPrefix>lib/</classpathPrefix>
        <mainClass>com.mypackage.DocumentIndex</mainClass>
      </manifest>
    </archive>

添加主类清单条目,或者将命令更改为
java-cp ElasticSearchUtility-1.0.0-SNAPSHOT.com.es.utility.DocumentIndex
您可以为创建的类发布pom.xml吗?解包jar并检查主条目是否存在于build/libs/META-INF/MANIFEST中。MF@TA-我也更新了pom.xml文件。请检查它,如果仍然存在问题,请告诉我
Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.5.1:copy-dependencies (copy-dependencies) on project ElasticSearchUtility: Error copying artifact from C:\Users\10641516\.m2\repository\org\apache\lucene\lucene-sandbox\7.1.0\lucene-sandbox-7.1.0.jar to D:\Karthikeyan\ElasticSearch\ElasticSearch_Tesing\target\dependency-
    [ERROR] jars\lucene-sandbox-7.1.0.jar: The filename, directory name, or volume label syntax is incorrect
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <classpathPrefix>lib/</classpathPrefix>
        <mainClass>com.mypackage.DocumentIndex</mainClass>
      </manifest>
    </archive>