有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaMaven:多模块WAR构建为库项目提供了“找不到主类”

我正在开发一个带有spring boot的多模块web项目,该项目应该作为war部署到tomcat中。我不想有一个用于CLI的嵌入式tomcat

该项目包括:

  • de.dpt。应用程序-应用程序的主要部分
  • de.dpt。gen-Library:实体和ORM映射(已生成)
  • 去商店化。api-库:Shopify REST api的实现

所有项目都不需要主类,但在运行我得到的“mvn安装”时仍然需要

org.apache.maven.lifecycle.LifecycleExecutionException: 
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:repackage (default) 
on project de.shopify.api: Execution default of goal 
org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:repackage failed: 
Unable to find main class

我不明白为什么“去商店化”模块。api“不会生成,而”de.dpt。gen’will,因为POM非常相似。你能帮我吗

家长/家长。xml(父pom)

<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>de.dpt</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>de.dpt.parent</name>
    <modules>
        <module>de.dpt.gen</module>
        <module>de.dpt.app</module>
        <!-- <module>de.dpt.amazon-batch</module> -->
        <module>de.shopify.api</module>
    </modules>



    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.6</java.version>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <!-- <tomcat.version>7.0.63</tomcat.version> -->
        <tomcat.version>7.0.59</tomcat.version>
        <servlet-api.version>3.0.0</servlet-api.version>
    </properties>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <!-- only 1.1.10 works for tomcat 7 -->
        <!-- <version>1.1.10.RELEASE</version> -->
        <!-- <version>1.2.5.RELEASE</version> -->
        <version>1.3.5.RELEASE</version><!-- to get a newer jackson version -->
    </parent>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <outputDirectory>webapps</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

de.dpt。gen/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>
    <parent>
        <groupId>de.dpt</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>de.dpt.gen</artifactId>
    <packaging>jar</packaging>


    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.10.Final</version>
        </dependency>


        <dependency><!-- handle conversion to json; supports circular references -->
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.voodoodyne.jackson.jsog</groupId>
            <artifactId>jackson-jsog</artifactId>
            <version>1.1</version>
        </dependency>

    </dependencies>


    <version>0.0.1-SNAPSHOT</version>
</project>

去商店化。api/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>
    <parent>
        <groupId>de.dpt</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>de.shopify.api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>


    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>



    </dependencies>

</project>

de.dpt。app/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>
    <parent>
        <groupId>de.dpt</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>de.dpt.app</artifactId>
    <packaging>war</packaging>

    <properties>
        <tomcat.version>7.0.59</tomcat.version>
        <org.mapstruct.version>1.1.0.Final</org.mapstruct.version>
    </properties>


<build><pluginManagement>
        <plugins>



            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <!-- NB! Set <version> to the latest released version of frontend-maven-plugin, 
                    like in README.md -->
                <version>1.0</version>

                <configuration>
                    <workingDirectory>src/main/resources/web-app</workingDirectory>
                </configuration>

                <executions>

                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
<nodeVersion>v5.3.0</nodeVersion>
<npmVersion>3.3.12</npmVersion>
                        </configuration>
                    </execution>

                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <!-- Optional configuration which provides for running any npm command -->
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>


                    <execution>
                        <id>grunt build</id>
                        <goals>
                            <goal>grunt</goal>
                        </goals>
                        <configuration>
                            <arguments>dist --no-color</arguments>
                        </configuration>
                    </execution>



                </executions>
            </plugin>


            <plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>2.2.4</version>
    <configuration>
        <defaultOutputDirectory>
            ${project.build.directory}/generated-sources
        </defaultOutputDirectory>
        <processors>
            <processor>org.mapstruct.ap.MappingProcessor</processor>
        </processors>
    </configuration>
    <executions>
        <execution>
            <id>process</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>process</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>
    </dependencies>
</plugin>



        </plugins>
        </pluginManagement>
    </build>


    <dependencies>

        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
            <version>${org.mapstruct.version}</version>
        </dependency>

        <dependency>
            <groupId>de.dpt</groupId>
            <artifactId>de.dpt.gen</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>


        <dependency>
            <groupId>de.dpt</groupId>
            <artifactId>de.dpt.amazonbatch</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>


        <dependency>
            <groupId>de.dpt</groupId>
            <artifactId>de.shopify.api</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>

        <dependency><!-- handle conversion to json; supports circular references -->
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>



        <dependency>
            <groupId>com.voodoodyne.jackson.jsog</groupId>
            <artifactId>jackson-jsog</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- http://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>





            <dependency>
                <groupId>org.thymeleaf.extras</groupId>
                <artifactId>thymeleaf-extras-springsecurity4</artifactId>
                <version>2.1.2.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>com.github.greengerong</groupId>
                <artifactId>prerender-java</artifactId>
                <version>1.6.4</version>
            </dependency>



            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>


            <dependency><!-- do not embed tomcat -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            <!-- don't ship this shit with the war!!! -->
            <dependency><!-- do not embed tomcat -->
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-core</artifactId>
                <scope>provided</scope>
            </dependency>



            <!--<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> 
                <scope>provided</scope> </dependency> -->


            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>




            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </dependency>


            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>

            <dependency>
                <groupId>net.coobird</groupId>
                <artifactId>thumbnailator</artifactId>
                <version>[0.4, 0.5)</version>
            </dependency>

            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.2</version>
            </dependency>



    </dependencies>




    <version>0.0.1-SNAPSHOT</version>
</project>

共 (1) 个答案

  1. # 1 楼答案

    如果您为{}选择Spring启动{a1},它会显示

    Once spring-boot-maven-plugin has been included in your pom.xml it will automatically attempt to rewrite archives to make them executable using the spring-boot:repackage goal.

    If you don’t specify a main class the plugin will search for a class with a public static void main(String[] args) method.

    因此,在您的模块“de.dpt.gen”中,此插件可能能够找到具有公共静态void main(String[]args)方法的类,而在模块“de.shopfify.api”中,可能没有任何具有公共静态void main(String[]args)方法的类

    如果您想将其作为独立可执行文件和普通war可部署文件运行,那么在父级/pom中。xml for spring-boot-maven-plugin您可以使用下面的main方法包含应用程序类,以显式地指定它

    <configuration>
            <mainClass>path.of.your.Application</mainClass>
            <outputDirectory>webapps</outputDirectory>
    </configuration> 
    

    如果您想在外部tomcat中部署普通war,那么您不需要在父pom中包含spring-boot-maven-plugin,因为您正在使用spring-boot-starter-parent,它将负责war文件的打包