maven clean install不会生成工件SNAPSHOT.jar

时间:2018-06-10 12:15:05

标签: java spring maven spring-boot

我正在Spring Boot和嵌入式服务器中迈出第一步。我发现这个In28Minutes Tutorial非常容易理解。现在我不得不尝试生成一个工件SNAPSHOT.jar文件,我将其导入到我的RCP项目中。运行maven clean install没有帮助。谁能帮我吗? Hier是一些信息:

  1. Spring Boot框架
  2. Spring Boot默认使用Tomcat作为嵌入式服务器容器
  3. Hier是控制台输出

    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ demo ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /Users/borisnguema/Documents/test-workspace/demo/src/test/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ demo ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ demo ---
    [INFO] 
    

    的pom.xml

    <?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>com.example</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>demo</name>
        <description>Demo project for Spring Boot</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.2.RELEASE</version>
            <relativePath /> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web-services</artifactId>
            </dependency>
    
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    
    </project>
    

    控制台输出(结束)

    [INFO] 
    [INFO] Results:
    [INFO] 
    [ERROR] Errors: 
    [ERROR]   DemoApplicationTests.initializationError » IllegalState Unable to find a @Spri...
    [INFO] 
    [ERROR] Tests run: 4, Failures: 0, Errors: 1, Skipped: 0
    [INFO] 
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 6.296 s
    [INFO] Finished at: 2018-06-10T14:41:23+02:00
    [INFO] Final Memory: 24M/437M
    [INFO] ------------------------------------------------------------------------
    [WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project demo: There are test failures.
    [ERROR] 
    [ERROR] Please refer to /Users/borisnguema/Documents/test-workspace/demo/target/surefire-reports for the individual test results.
    [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
    

    主:

    package bookmarks;
    
    import java.util.Arrays;
    
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.Bean;
    
    import bookmarks.entity.Account;
    import bookmarks.entity.Bookmark;
    import bookmarks.repository.IAccountRepository;
    import bookmarks.repository.IBookmarkRepository;
    
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
        @Bean
        CommandLineRunner init(IAccountRepository accountRepository, IBookmarkRepository bookmarkRepository) {
            return (evt) -> Arrays.asList("jhoeller,dsyer,pwebb,ogierke,rwinch,mfisher,mpollack,jlong".split(","))
                    .forEach(a -> {
                        Account account = accountRepository.save(new Account(a, "password"));
                        bookmarkRepository.save(new Bookmark(account, "http://bookmark.com/1/" + a, "A description"));
                        bookmarkRepository.save(new Bookmark(account, "http://bookmark.com/2/" + a, "A description"));
                    });
        }
    }
    

2 个答案:

答案 0 :(得分:0)

所以我会尝试假设,你没有创建主类,在某个地方,你应该有类似的东西:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.410 s
[INFO] Finished at: 2018-06-10T18:26:06+03:00
[INFO] Final Memory: 32M/1266M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) on project demo: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage failed: Unable to find main class -> [Help 1]

为了使这个工作添加主类到你的src / main / java文件夹

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }
}

在日志末尾执行mvn clean install的结果应该是:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.043 s
[INFO] Finished at: 2018-06-10T18:29:38+03:00
[INFO] Final Memory: 40M/1004M
[INFO] ------------------------------------------------------------------------

在目标中,您将获得demo-0.0.1-SNAPSHOT.jar

希望这会有所帮助。

答案 1 :(得分:0)

我欠你们一个道歉。我搞砸了。我有两个测试包,如下图所示。所以第一个是正确的设置,但第二个是没有。这就是为什么我有一次测试失败我无法解释的原因。现在,我删除了包,Maven运行槽。尽管如此,我还是要感谢你们帮助我解决一个不是第一个问题的问题:-)

enter image description here