直接回答:用 system 作用域引本地 jar 能编译但不会被打进产物,正确做法是把它 install 到本地仓库再正常依赖,或者用打包插件的 includeSystemScope 把依赖一起塞进去。

打包会有问题

root lib-A

当前是需要直接打root的jar包,但是lib包下面有直接引用的本地jar并不在maven仓库当中使用如下

格式如下:

1
2
3
4
5
6
7
<dependency>
<groupId>com.shentong</groupId>
<artifactId>pinyinAnalyzer</artifactId>
<version>4.3.1</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/main/resources/lib/pinyinAnalyzer4.3.1.jar</systemPath>
</dependency>

如果打包中如果有测试代码编译不通过的可用参考添加

1
2
3
4
5
6
7
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>

我后面发现打的jar包lib文件夹下面的确是有lib-A项目,但是啊就是跑的后面一旦涉及引用lib-A下面的本地第三方jar就说类找不到网上有人给出如下解决方案

1
2
3
4
5
6
7
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>

我分别在lib-A和root项目下添加了,神奇的事发生了,打包的后服务可以运行,但是lib-A下面的controller全都没有,对应的请求都是404,人都快裂开了

只能排除法先注释root下发现不行,后面注释lib-A下居然成功了,真TMD邪门

补充maven install 包含外部jar的打包情况-------

参考链接

在maven的pom文件中引用本地的jar

1
2
3
4
5
6
7
8
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/lib/pinyin4j-2.5.0.jar</systemPath>-->
<systemPath>${pom.basedir}/src/main/resources/lib/pinyin4j-2.5.1.jar</systemPath>
</dependency>

但是打包时会报错

should not point at files within the project directory dependencies.dependency.systemPath

在stackoverflow上有两种方式

第一种是pom中添加jar所在文件夹的仓库

1
2
3
4
5
6
7
<repositories>
<repository>
<id>localrepository</id>
<url>file://${project.basedir}/src/main/resources/lib</url>
</repository>

</repositories>

但是在打包的时候还是会出问题

第二种使用plugin来实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<phase>compile</phase>
<!-- <goals>
<goal>copy-dependencies</goal>
</goals>-->
<configuration>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
<packaging>jar</packaging>
<file>${pom.basedir}/src/main/resources/lib/pinyinAnalyzer4.3.1.jar</file>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

tips 下面的两种尝试过失败也列出来

  1. 使用configuration复制来自于网络和正确的配置有出入

xml pinyin4j compile ${pom.basedir}/src/main/resources/lib/pinyin4j-2.5.0.jar default com.belerweb pinyin4j 2.5.0 jar true pinyin4j

  1. 使用clean
1
2
3
4
5
6
7
8
9
10
11
<execution>
<id>pinyinAnalyzer</id>
<phase>clean</phase>
<configuration>
<file>${pom.basedir}/src/main/resources/lib/pinyinAnalyzer4.3.1.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.shentong</groupId> <artifactId>pinyinAnalyzer</artifactId>
<version>4.3.1</version> <packaging>jar</packaging>
<generatePom>true</generatePom> </configuration>
<goals> <goal>install-file</goal>
</goals> </execution>
  1. 使用phase>init</phase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<execution>
<id>pinyinAnalyzer</id>
<phase>init</phase>
<configuration>
<file>${pom.basedir}/src/main/resources/lib/pinyinAnalyzer4.3.1.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.shentong</groupId>
<artifactId>pinyinAnalyzer</artifactId>
<version>4.3.1</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
hconfiguration> <goals>
<goal>install-file</goal>
</goals>
</execution>

之前一直用IntelliJ IDEA 的直接下载jar包,但是这次一直下载不下来指定版本jar包,看本地的代码库localRepository本地没有,看本地部署的maven中心,所以使用了参考地址

  1. 创建pom.xml 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Spider</groupId>
<artifactId>Spider</artifactId>
<version>1.0</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
  1. 使用mvn命令 下载后在本地仓库看到, 然后在IntelliJ IDEA刷新
1
mvn dependency:copy-dependencies

实测有用的打包本地jar包方法

1
2
3
4
5
6
7
<dependency>
<groupId>com.shentong</groupId>
<artifactId>pinyinAnalyzer</artifactId>
<version>4.3.1</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/main/resources/lib/pinyinAnalyzer4.3.1.jar</systemPath>
</dependency>
1
2
3
4
5
6
7
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{
"schema": "物模型结构定义的访问URL。",
"profile": {
"productKey": "当前产品的ProductKey。"
},
"properties": [
{
"identifier": "属性唯一标识符(物模型模块下唯一)。",
"name": "属性名称",
"accessMode": "属性读写类型:只读(r)或读写(rw)。",
"required": "是否是标准功能的必选属性:是(true),否(false)。",
"dataType": {
"type": "属性类型: int(原生)、float(原生)、double(原生)、text(原生)、date(String类型UTC毫秒)、bool(0或1的int类型)、enum(int类型,枚举项定义方法与bool类型定义0和1的值方法相同)、struct(结构体类型,可包含前面7种类型,下面使用"specs":[{}]描述包含的对象)、array(数组类型,支持int、double、float、text、struct)。",
"specs": {
"min": "参数最小值(int、float、double类型特有)。",
"max": "参数最大值(int、float、double类型特有)。",
"unit": "属性单位(int、float、double类型特有,非必填)。",
"unitName": "单位名称(int、float、double类型特有,非必填)。",
"size": "数组元素的个数,最大512(array类型特有)。",
"step": "步长(text、enum类型无此参数)。",
"length": "数据长度,最大10240(text类型特有)。",
"0": "0的值(bool类型特有)。",
"1": "1的值(bool类型特有)。",
"item": {
"type": "数组元素的类型(array类型特有)。"
}
}
}
}
],
"events": [
{
"identifier": "事件唯一标识符(物模型模块下唯一,其中post是默认生成的属性上报事件)。",
"name": "事件名称。",
"desc": "事件描述。",
"type": "事件类型(info、alert、error)。",
"required": "是否是标准功能的必选事件:是(true),否(false)。",
"outputData": [
{
"identifier": "参数唯一标识符。",
"name": "参数名称。",
"dataType": {
"type": "属性类型: int(原生)、float(原生)、double(原生)、text(原生)、date(String类型UTC毫秒)、bool(0或1的int类型)、enum(int类型,枚举项定义方法与bool类型定义0和1的值方法相同)、struct(结构体类型,可包含前面7种类型,下面使用"specs":[{}]描述包含的对象)、array(数组类型,支持int、double、float、text、struct)。",
"specs": {
"min": "参数最小值(int、float、double类型特有)。",
"max": "参数最大值(int、float、double类型特有)。",
"unit": "属性单位(int、float、double类型特有,非必填)。",
"unitName": "单位名称(int、float、double类型特有,非必填)。",
"size": "数组元素的个数,最大512(array类型特有)。",
"step": "步长(text、enum类型无此参数)。",
"length": "数据长度,最大10240(text类型特有)。",
"0": "0的值(bool类型特有)。",
"1": "1的值(bool类型特有)。",
"item": {
"type": "数组元素的类型(array类型特有)。"
}
}
}
}
],
"method": "事件对应的方法名称(根据identifier生成)。"
}
],
"services": [
{
"identifier": "服务唯一标识符(物模型模块下唯一,其中set/get是根据属性的accessMode默认生成的服务)。",
"name": "服务名称。",
"desc": "服务描述。",
"required": "是否是标准功能的必选服务:是(true),否(false)。",
"callType": "async(异步调用)或sync(同步调用)。",
"inputData": [
{
"identifier": "入参唯一标识符。",
"name": "入参名称。",
"dataType": {
"type": "属性类型: int(原生)、float(原生)、double(原生)、text(原生)、date(String类型UTC毫秒)、bool(0或1的int类型)、enum(int类型,枚举项定义方法与bool类型定义0和1的值方法相同)、struct(结构体类型,可包含前面7种类型,下面使用"specs":[{}]描述包含的对象)、array(数组类型,支持int、double、float、text、struct)。",
"specs": {
"min": "参数最小值(int、float、double类型特有)。",
"max": "参数最大值(int、float、double类型特有)。",
"unit": "属性单位(int、float、double类型特有,非必填)。",
"unitName": "单位名称(int、float、double类型特有,非必填)。",
"size": "数组元素的个数,最大512(array类型特有)。",
"step": "步长(text、enum类型无此参数)。",
"length": "数据长度,最大10240(text类型特有)。",
"0": "0的值(bool类型特有)。",
"1": "1的值(bool类型特有)。",
"item": {
"type": "数组元素的类型(array类型特有)。"
}
}
}
}
],
"outputData": [
{
"identifier": "出参唯一标识符。",
"name": "出参名称。",
"dataType": {
"type": "属性类型: int(原生)、float(原生)、double(原生)、text(原生)、date(String类型UTC毫秒)、bool(0或1的int类型)、enum(int类型,枚举项定义方法与bool类型定义0和1的方法相同)、struct(结构体类型,可包含前面7种类型,下面使用"specs":[{}]描述包含的对象)、array(数组类型,支持int、double、float、text、struct)。",
"specs": {
"min": "参数最小值(int、float、double类型特有)。",
"max": "参数最大值(int、float、double类型特有)。",
"unit": "属性单位(int、float、double类型特有,非必填)。",
"unitName": "单位名称(int、float、double类型特有,非必填)。",
"size": "数组元素的个数,最大512(array类型特有)。",
"step": "步长(text、enum类型无此参数)。",
"length": "数据长度,最大10240(text类型特有)。",
"0": "0的值(bool类型特有)。",
"1": "1的值(bool类型特有)。",
"item": {
"type": "数组元素的类型(array类型特有)。"
}
}
}
}
],
"method": "服务对应的方法名称(根据identifier生成)。"
}
],
//仅自定义模块的TSL中有以下参数。
"functionBlockId": "自定义模块的唯一标识符,模块ID。",
"functionBlockName": "自定义模块名称。",

//当产品下添加了自定义模块,默认模块TSL中会包含以下参数,表示已添加的自定义模块列表。
"functionBlocks": [
{
"functionBlockId": "自定义模块的唯一标识符,模块ID。",
"functionBlockName": "自定义模块名称。",
"productKey": "产品ProductKey。"
}
]
}

这篇笔记整理自我自己的实践记录,如果做法有出入,或者你踩过别的坑,欢迎到留言板一起聊聊。

站内搜索

没有找到内容!