spingboot项目运行报错:xxx.jar中没有主清单属性
原创
©著作权归作者所有:来自51CTO博客作者wu_55555的原创作品,请联系作者获取转载授权,否则将追究法律责任
报错
项目为spingboot项目,打包成了jar包。打包时就发现文件太小,只有200多K,一运行果然报错。
解决
pom.xml中添加
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot-version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
重新打包,发现jar大小正常了,但是再运行出现了另外一个错(这里是我项目的原因,针对如题错误,到此应该解决了)
报错 unsupportedClassVersionError
1、再次运行还是报错
unsupportedClassVersionError PreView features are not enabled for xxx try running with '--enable-preview'
根据提示,以–enable-preview运行项目,但是还是报错
去掉了pom.xml中enable-preview属性
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF-8</encoding>
<release>14</release>
<!--<compilerArgs>--enable-preview</compilerArgs>-->
<!--idea不重置language level-->
<source>11</source>
<target>11</target>
<!--idea不重置language level-->
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot-version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!--<argLine>--enable-preview</argLine>-->
</configuration>
</plugin>
2、打包运行又报错
jdbcTemplate that could not found
去掉了启动类中@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
里的(exclude= {DataSourceAutoConfiguration.class})
注:exclude是在服务中不需要访问数据库时添加,如果需要访问则不要添加
又报错
failed to configure a datasource 'url' attributu is not specified and no embedded datasource
添加了resources目录的扫描
<resources>
<resource>
<!-- xml放在java目录下-->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
运行成功
问题解决