在IDE中的同一项目中,Jar不会启动

时间:2018-02-07 14:25:16

标签: java spring maven

有点混乱的情况。在我的IDE中我无法运行jar文件一切正常。顺便说一句,整个项目中只有一个模块就是这样。 所以,有我的stacktrace

    [WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: File [/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] referenced by given URL [file:/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] does not exist
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) ~[spring-context-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) ~[spring-context-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at com.acme.ept.cra.gateway.sfdc.SFDCGatewayApplication.main(SFDCGatewayApplication.java:97) [classes!/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [sfdc-gateway-1.0.0.1.0.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [sfdc-gateway-1.0.0.1.0.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [sfdc-gateway-1.0.0.1.0.jar:na]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [sfdc-gateway-1.0.0.1.0.jar:na]
Caused by: java.lang.IllegalArgumentException: File [/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] referenced by given URL [file:/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] does not exist
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.archive.internal.JarProtocolArchiveDescriptor.<init>(JarProtocolArchiveDescriptor.java:71) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:55) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:70) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:725) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:221) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider$1.<init>(SpringHibernateJpaPersistenceProvider.java:49) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    ... 23 common frames omitted
[WARN] org.springframework.boot.SpringApplication - Error handling failed (Error creating bean with name 'assignInteractionContainer': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined)
[ERROR] org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: File [/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] referenced by given URL [file:/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] does not exist
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) ~[spring-context-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) ~[spring-context-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
    at com.acme.ept.cra.gateway.sfdc.SFDCGatewayApplication.main(SFDCGatewayApplication.java:97) [classes!/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [sfdc-gateway-1.0.0.1.0.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [sfdc-gateway-1.0.0.1.0.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [sfdc-gateway-1.0.0.1.0.jar:na]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [sfdc-gateway-1.0.0.1.0.jar:na]
Caused by: java.lang.IllegalArgumentException: File [/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] referenced by given URL [file:/D:/temp/sfdc-gateway-1.0.0.1.0.jar!/BOOT-INF/classes] does not exist
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.archive.internal.JarProtocolArchiveDescriptor.<init>(JarProtocolArchiveDescriptor.java:71) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:55) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:70) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:725) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:221) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider$1.<init>(SpringHibernateJpaPersistenceProvider.java:49) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
    ... 23 common frames omitted

还有我的pom.xml构建部分:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.acme.ept.cra.gateway.sfdc.SFDCGatewayApplication</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.0.M6</version>
            <configuration>
                <jvmArguments>
                    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
                </jvmArguments>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

我100%确定这些类存在,有一张图片:enter image description here 不幸的是,谷歌没有帮助我。那是什么原因? 提前谢谢。

P.S。我无法更新高于1.2.5的弹簧启动

增加:清单内容:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: beleych
Start-Class: com.acme.ept.cra.gateway.sfdc.SFDCGatewayApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Version: 2.0.0.M6
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_144
Main-Class: org.springframework.boot.loader.JarLauncher

3 个答案:

答案 0 :(得分:0)

你真的需要:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.acme.ept.cra.gateway.sfdc.SFDCGatewayApplication</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

Spring Boot应用中? Spring Boot可能会在没有额外插件的情况下做到这一点。

答案 1 :(得分:0)

从stacktrace看来,你试图从SFDCGatewayApplication类中打开它,这是stacktrace(第2行)的重要部分:

at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) [spring-boot-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
at com.acme.ept.cra.gateway.sfdc.SFDCGatewayApplication.main(SFDCGatewayApplication.java:97) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]

答案 2 :(得分:0)

好的伙计们。谢谢你的帮助。问题出现在旧版本的hibernate中。 原因: hibernate在jar中寻找实体(但它们都没有,它们不应该在那里)。在早期版本的hibernate中,在这种情况下它引发了一个错误。在当前版本中,它仅引发[WARN]。 我想说错误描述是非常不清楚的。所以我的解决方案是:

添加依赖项:

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

   <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>5.2.10.Final</version>
   </dependency>

并排除这个:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
       <exclusions>
          <exclusion>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-entitymanager</artifactId>
          </exclusion>
          <exclusion>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-core</artifactId>
          </exclusion>
       </exclusions>
    </dependency>