後無法找到或加載主類,當我設置我的pom.xml時,我的應用程序仍然無法運行,說它無法找到或加載主類。 我安裝我的pom.xml作爲陳述hereMaven在正確設置插件
我的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>com.example</groupId>
<artifactId>EditPropertiesFile</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.example.EditPropertiesFile.Main</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>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-configuration/commons-configuration -->
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</project>
我用命令MVN清潔編譯組件:單將應用程序打包,然後用java的運行 - 罐子outputedJar.jar
這是MANIFEST.MF這是罐內,說:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: xxxx
Build-Jdk: 1.8.0_121
Main-Class: com.example.EditPropertiesFile.Main
然而,當我跑,我得到一個錯誤:
Error: Could not find or load main class com.example.EditPropertiesFile.Main
我不知道還有什麼我可以試試,因爲我有這麼嘗試了所有在各種答案,他們似乎都解決其他一些問題。
編輯: 輸出運行時,命令:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EditPropertiesFile 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EditPropertiesFile ---
[INFO] Deleting D:\Users\xxxx\Documents\Java_workspace\EditPropertiesFile\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EditPropertiesFile ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Users\xxxx\Documents\Java_workspace\EditPropertiesFile\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ EditPropertiesFile ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-assembly-plugin:2.4:single (default-cli) @ EditPropertiesFile ---
[WARNING] Cannot include project artifact: com.example:EditPropertiesFile:jar:1.0; it doesn't have an associated file or directory.
[INFO] Building jar: D:\Users\xxxx\Documents\Java_workspace\EditPropertiesFile\target\EditPropertiesFile-1.0-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.525 s
[INFO] Finished at: 2017-08-16T21:17:56+02:00
[INFO] Final Memory: 13M/225M
[INFO] ------------------------------------------------------------------------
裏面的jar文件沒有文件Main.java
我的項目的結構:
我現在編輯的問題。 Main.java不在我輸出的jar中。 –
我不確定目錄結構是否是問題。我編輯了問題,在最後給出了項目結構圖 –
,如果您使用命令行中的mvn,那麼您可能需要確保目錄結構符合mvn默認值。也許你可以嘗試一下我剛纔提到的結構,如果還沒有完成的話。 – Sharman25