首页 新闻 会员 周边 捐助

将极为简单的springBoot项目打成jar包运行问题

0
[待解决问题]

我是使用IDEA 工具自身build Artifacts打的jar包,项目使用到了mybatis,mysql,添加了web模块。开发工具里可以直接运行没问题,但是我在本地D盘使用java -jar name.jar命令运行的时候,弹出错误

不知道怎么解决,网络上的解决方案都试了一遍啦,什么换注解啦,加pom依赖啦,我将pom贴出来一下,这里没找到插入代码,我直接贴出来啦

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <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>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.3</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <!--<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>-->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--这里写上main方法所在类的路径-->
                <configuration>
                    <mainClass>com.example.tenant.TenantApplication</mainClass>
                </configuration>

                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
    <resources>
        <resource>
            <!--src/main/resources :文件资源路径-->
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>

</project>

根目录97的主页 根目录97 | 初学一级 | 园豆:8
提问于:2020-07-10 17:45
< >
分享
所有回答(3)
0

你直接用Maven的package看看

biubiubiuovo | 园豆:211 (菜鸟二级) | 2020-07-10 21:23
0

同意楼上使用maven打包试一下

8号位 | 园豆:596 (小虾三级) | 2020-07-19 21:23

一样不行哦,报一样的错误

支持(0) 反对(0) 根目录97 | 园豆:8 (初学一级) | 2020-07-20 09:44
0

pom.xml 中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope>
</dependency>
compile 属于编译阶段引用,试着把“<scope>compile</scope>” 去掉

不安分的黑娃 | 园豆:169 (初学一级) | 2021-01-20 21:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册