2017-11-11 30 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/