maven 打包 jar 注意事项 经及 centos 7 jar 安装为服务

一、IDEA中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<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>com.familyxiao</groupId>
    <artifactId>GetGoodWeb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>GetGoodWeb</name>
    <packaging>jar</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
         
        <!-- mybatis依赖 -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!-- 引入thymelaf 则不需要引入web依赖,若不需要thymelaf则需要添加spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
         
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-json</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>
         
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.2.3</version>
            <classifier>jdk15</classifier>
        </dependency>
 
        <!-- mysql依赖 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
         
         <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
<!--         <scope>provided</scope>-->
            <!-- provided 表明该包只在编译和测试的时候使用,去除默认的tomcat -->
            <!--<scope>provided</scope>-->
            <version>1.5.2.RELEASE</version>
            <scope>compile</scope>
        </dependency>
<!--     <dependency>-->
<!--         <groupId>javax.servlet</groupId>-->
<!--         <artifactId>javax.servlet-api</artifactId>-->
<!--         <version>3.1.0</version>-->
<!--     </dependency>-->
    </dependencies>
    <build>
    <plugins>
    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <useUniqueVersions>false</useUniqueVersions>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>com.familyxiao.Application</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <!-- 要使生成的jar可运行,需要加入此插件 -->
<!--     <plugin>-->
<!--         <groupId>org.springframework.boot</groupId>-->
<!--         <artifactId>spring-boot-maven-plugin</artifactId>-->
<!--     </plugin>-->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.1.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

  

参见:https://blog.csdn.net/u011712163/article/details/89705295

 

Centos7 发布jar包: https://www.cnblogs.com/raorao1994/p/9566222.html

 

 

将springboot打包成的jar文件做成windows服务

首先使用 java -jar *.jar 看一下有没有报错。

1.在idea中用maven将程序打成jar,放到运行的目录中。 

2.去github上面下载winsw: https://github.com/kohsuke/winsw/releases

3. 将WinSW.NET4.exe文件复制到java程序所在文件夹中

4.将java程序重命名,去掉名称中的“.”。例如test-1.0.jar ----> test.jar

5.将WinSW.exe重命名为test.exe(和jar同名) 

6. 新建一个xml文件,命名为test.xml,写入以下内容(还有一些参数自己去看github说明):

<service>

<id>test</id>

<name> test </name>

<description>This is test service.</description>

<!-- java环境变量 -->

<env name="JAVA_HOME" value="%JAVA_HOME%"/>

<executable>java</executable>

<arguments>-jar "E:\springboot\ test.jar"</arguments>

<!-- 开机启动 -->

<startmode>Automatic</startmode>

<!-- 日志配置 -->

<logpath>%BASE%\log</logpath>

<logmode>rotate</logmode>

</service>

如果没有配置环境变量,直接将三个文件扔到java的bin目录下运行。去掉标签<env name="JAVA_HOME" value="%JAVA_HOME%"/>

 

7.命令行定位到当前目录,执行:

test.exe install

8. 去windows服务列表中启动程序。

(如果需要更新程序,只需要先将服务停止,再将新文件重命名为test.jar,最后启动服务就行了)

 

posted @   三瑞  阅读(378)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示