2017-04-20 139 views
0

我正在使用IntelliJ IDEA进行Spring Boot项目,并且一切正常。我没有任何问题在IntelliJ IDEA中运行和测试应用程序。无论我将其配置为“应用程序”还是“弹簧启动”(从运行/编辑配置菜单),它都可以运行。由IntelliJ IDEA生成的Spring Boot项目的工件导致错误

但是,在创建工件并尝试使用“java -jar AppName 。罐”。它喷出了这样的错误:

找不到任何财产来源键 'spring.profiles.active'

产生的原因:java.lang.IllegalArgumentException异常:无在META-INF/spring.factories中找到自动配置类。如果您使用自定义打包,请确保该文件是正确的。

我提取了jar文件和spring.factories等文件确实在文件夹“META-INF”中。

我怀疑问题的原因是类路径。当我从IntelliJ IDEA中运行它时,我注意到它在“使用模块的类路径”中设置为模块。但是,在神器中,我无法正确设置设置。

您认为问题的原因是什么?我认为这是班级之路。如果不是,还能有什么?请帮忙!

我在这里提供我的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>org.kurento.tutorial</groupId> 
    <artifactId>kurento-tutorial</artifactId> 
    <version>6.6.1-SNAPSHOT</version> 
</parent> 

<artifactId>WebRTCLiveApp</artifactId> 
<packaging>jar</packaging> 

<name>WebRTCLiveApp</name> 
<description>Company Live App</description> 

<licenses> 
    <license> 
     <name>Apache 2.0</name> 
     <url>http://www.apache.org/licenses/LICENSE-2.0</url> 
     <distribution>repo</distribution> 
    </license> 
</licenses> 

<organization> 
    <name>Kurento</name> 
    <url>http://www.kurento.org</url> 
</organization> 

<developers> 
    <developer> 
     <id>kurento.org</id> 
     <name>-kurento.org Community</name> 
     <organization>Kurento.org</organization> 
     <organizationUrl>http://www.kurento.org</organizationUrl> 
    </developer> 
</developers> 

<properties> 

    <!-- Main class --> 
    <start-class>com.company.live.webrtc.WebRTCLiveApp</start-class> 

</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-websocket</artifactId> 
    </dependency> 

    <!-- Kurento --> 
    <dependency> 
     <groupId>org.kurento</groupId> 
     <artifactId>kurento-client</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.kurento</groupId> 
     <artifactId>kurento-utils-js</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>webjars-locator</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars.bower</groupId> 
     <artifactId>bootstrap</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>draggabilly</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars.bower</groupId> 
     <artifactId>demo-console</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars.bower</groupId> 
     <artifactId>adapter.js</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars.bower</groupId> 
     <artifactId>jquery</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars.bower</groupId> 
     <artifactId>ekko-lightbox</artifactId> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <configuration> 
       <mainClass>${start-class}</mainClass> 
       <layout>ZIP</layout> 
       <classifier>exec</classifier> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <configuration> 
       <mainClass>${start-class}</mainClass> 
      </configuration> 
     </plugin> 
    </plugins> 

    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>false</filtering> 
     </resource> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
      <includes> 
       <include>banner.txt</include> 
      </includes> 
     </resource> 
    </resources> 
</build> 

<profiles> 
    <profile> 
     <id>default</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-assembly-plugin</artifactId> 
        <configuration> 
         <descriptor>src/assembly/bin.xml</descriptor> 
         <finalName>${project.artifactId}-${project.version}</finalName> 
         <appendAssemblyId>false</appendAssemblyId> 
        </configuration> 
        <executions> 
         <execution> 
          <phase>package</phase> 
          <goals> 
           <goal>single</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-antrun-plugin</artifactId> 
        <executions> 
         <execution> 
          <phase>package</phase> 
          <configuration> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
    <profile> 
     <id>no-assembly</id> 
    </profile> 
</profiles> 

我已经搜索并尝试其他例子/解决方案,并没有奏效。

请帮忙!谢谢!

+0

第一个错误看起来像没有找到“.properties”文件的问题。你的'.properties'文件位于哪里?它们是否包含在JAR清单中的类路径中? – wheeler

+0

您需要使用spring boot maven插件来构建可执行jar。 Spring引导可执行文件jar与常规可执行jar有不同的结构。 – jny

+0

不要在initellij中创建artifiact ...使用manve与spring引导插件(专为此设计)。我建议删除exec插件,程序集插件和antrun插件。这是Spring Boot Plugin的一项任务。 –

回答

0

问题已解决。

在器物的IntelliJ从模块对话框创建JAR,我不得不

  1. 选择“通过清单复制到输出目录和链接”选项
  2. 确保META-INF/MANIFEST.INF文件设置为“src/main/resources”

现在一切正常(花费整个下午之后)。

+1

您正在使用Spring Boot,因此也应该使用Spring Boot Maven插件来创建可执行文件。你正在围绕框架而不是框架。 –

+0

Maven是构建工具,并确保您使用它。 IntelliJ不是一个好的选择,因为你不允许它与Jenkins等CI工具集成。我建议添加spring boot maven插件并继续用maven构建,尽管你已经解决了它。 –

相关问题