2017-11-11 83 views
2

我正在使用Maven,當它試圖將它變成一個jar文件時,它表示編譯成功,但它說沒有編譯源。Maven:錯過了'target'文件夾下的編譯類

[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building UrbanAC Booking Manager 1.2.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ UrbanAC -- - 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,  i.e. build is platform dependent! 
[INFO] Copying 24 resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ UrbanAC --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @  UrbanAC --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,  i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory C:\Users\Akhil Maganti\eclipse- workspace\New\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @  UrbanAC --- 
[INFO] No sources to compile 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ UrbanAC --- 
[INFO] No tests to run. 
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ UrbanAC --- 
[INFO] Building jar: C:\Users\Akhil Maganti\eclipse-workspace\New\target\UrbanAC-1.2.1-SNAPSHOT.jar 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.413 s 
[INFO] Finished at: 2017-11-11T00:19:22+00:00 
[INFO] Final Memory: 11M/245M 
[INFO] ------------------------------------------------------------------------ 

這是顯示的錯誤,我不知道爲什麼顯示。 enter image description here

+0

如果不認真重新編譯pom.xml文件,則無法使用普通的Eclipse佈局。 –

+0

按照約定,表示'src/main/java' Java源文件。 'src/main/resources'資源如屬性文件等'src/test/java'單元測試Java源代碼。單元測試的'src/test/resources'資源。 – khmarbaise

回答

1

No sources to compile與單元測試有關。

生產代碼已編譯。它說:

Nothing to compile - all classes are up to date

如果你真的需要你的應用程序的jar文件,你可以通過maven-assembly-plugin做到這一點:

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <mainClass>your.main.class</mainClass> 
        </manifest> 
       </archive> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>install</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

現在運行mvn clean installtarget文件夾下找到一個jar文件。

並確保您的項目結構遵循此standard

+0

這次它仍然說'沒有編譯源文件,並且沒有說'沒有編譯 - 所有的類都是最新的' – DaBoss

1

一旦你有了正確的位置源和資源文件,你可以在pom.xml中添加maven-jar-plugin和運行命令mvn jar:jar

src/main/java  - sources 
src/main/resources - resources 

參考:https://maven.apache.org/plugins/maven-jar-plugin/

<project> 
    ... 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>3.0.2</version> 
     <configuration> 
      <archive> 
      <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> 
      </archive> 
     </configuration> 
     ... 
     </plugin> 
    </plugins> 
    </build> 
    ... 
</project> 

注意:我通常不給非文檔鏈接,因爲它們可能會被刪除或過期,但這裏是我從中學到很長時間的示例https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/