简体   繁体   English

maven全新安装不会生成工件SNAPSHOT.jar

[英]maven clean install does not generate an artifact SNAPSHOT.jar

I'm making my first steps in Spring Boot and embedded servers. 我正在Spring Boot和嵌入式服务器中迈出第一步。 I found this In28Minutes Tutorial which is pretty easy to follow. 我发现此In28Minutes教程非常容易遵循。 Now I stuck trying to generate an artifact SNAPSHOT.jar file, which I would import into my RCP-project. 现在,我坚持尝试生成工件SNAPSHOT.jar文件,将其导入到我的RCP项目中。 Running maven clean install didn't help. 运行maven clean install没有帮助。 Can anyone help me out? 谁能帮我吗? Hier are the some informations: 更高的是一些信息:

  1. Spring Boot framework Spring Boot框架
  2. Spring Boot Starts use Tomcat by default as an embedded server container Spring Boot Starts默认使用Tomcat作为嵌入式服务器容器

Hier is the console output 更高的是控制台输出

[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 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>

Console output (End) 控制台输出(完)

[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

Main: 主要:

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"));
                });
    }
}

So I will try to assume, that you didn't create main class and somewhere down you should have something like that: 因此,我将假设您没有创建主类,而在某些地方应该有类似的东西:

[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]

For makeing this working add main class to your src/main/java folder 为了使此工作正常,将主类添加到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);
    }
}

In result of execution of mvn clean install at the end of log you should have: 由于在日志末尾执行了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] ------------------------------------------------------------------------

And in target you will get your demo-0.0.1-SNAPSHOT.jar 在目标中,您将获得demo-0.0.1-SNAPSHOT.jar

Hope this will help. 希望这会有所帮助。

I owe you guys an apology. 我欠你们一个道歉。 I messed up big. 我搞砸了。 I was having two test packages as you can see on the picture below. 我有两个测试包,如下图所示。 So the first is rightfully set up, but the second wasn't. 因此,第一个设置正确,但第二个则没有。 That is the reason why I had one test failure I couldn't explain. 这就是为什么我无法解释的一个测试失败的原因。 Now, I removed the package and Maven runs trough. 现在,我删除了程序包,Maven陷入低谷。 Nevertheless, I want to thank you guys for trying to help me with a problem that wasn't really one in the first place :-) 不过,我要感谢你们试图帮助我解决最初不是一个真正问题的问题:-)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM