Browse Source

减少打包体积

zhenghao 4 tháng trước cách đây
mục cha
commit
2788fc3118
3 tập tin đã thay đổi với 187 bổ sung159 xóa
  1. 3 0
      .gitignore
  2. 40 26
      README.md
  3. 144 133
      pom.xml

+ 3 - 0
.gitignore

@@ -29,3 +29,6 @@ build/
 
 ### VS Code ###
 .vscode/
+
+!lib
+!lib.*

+ 40 - 26
README.md

@@ -13,32 +13,32 @@ ollama (linux环境)
 ###创建maven配置文件(maven.xml)
 ```xml
 <settings>
-  <localRepository>存储文件目录(如D:/repo)</localRepository>
-  <mirrors>
-    <mirror>
-      <id>public</id>
-      <url>https://maven.aliyun.com/repository/public</url>
-      <mirrorOf>public,!bladex</mirrorOf>
-    </mirror>
-    <mirror>
-      <id>central</id>
-      <url>https://maven.aliyun.com/repository/central</url>
-      <mirrorOf>central,!bladex</mirrorOf>
-    </mirror>
-  </mirrors>
-  <servers>
-    <server>
-      <id>bladex</id>
-      <configuration>
-        <httpHeaders>
-          <property>
-            <name>Authorization</name>
-            <value>token c02fc9fe46326c7706fb65c233ac2c7ba1af6dfe</value>
-          </property>
-        </httpHeaders>
-      </configuration>
-    </server>
-  </servers>
+    <localRepository>D:/repository</localRepository>
+    <mirrors>
+        <mirror>
+            <id>public</id>
+            <url>https://maven.aliyun.com/repository/public</url>
+            <mirrorOf>public,!bladex</mirrorOf>
+        </mirror>
+        <mirror>
+            <id>central</id>
+            <url>https://maven.aliyun.com/repository/central</url>
+            <mirrorOf>central,!bladex</mirrorOf>
+        </mirror>
+    </mirrors>
+    <servers>
+        <server>
+            <id>bladex</id>
+            <configuration>
+                <httpHeaders>
+                    <property>
+                        <name>Authorization</name>
+                        <value>token c02fc9fe46326c7706fb65c233ac2c7ba1af6dfe</value>
+                    </property>
+                </httpHeaders>
+            </configuration>
+        </server>
+    </servers>
 </settings>
 ```
 ###配置idea maven环境
@@ -85,4 +85,18 @@ nohup ~/ollama serve > ~/ollama.log 2>&1 &
 ####开启会话qwen2:7b
 ```shell
 ~/ollama run qwen2:7b
+```
+
+####打包启动
+```shell
+#打包
+maven -> ragchat -> clean
+maven -> ragchat -> package
+
+# 启动
+nohup java -Dloader.path='lib/' -jar ragchat.jar > ragchat.log 2>&1 &
+
+# 添加依赖包到当前lib目录(首次/或依赖包更新时)
+# 将lib打包并解压到与jar包同级目录
+mvn dependency:copy-dependencies -DoutputDirectory=.\lib  -DincludeScope=runtime
 ```

+ 144 - 133
pom.xml

@@ -1,137 +1,148 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project>
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.springframework.boot</groupId>
-		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>3.3.2</version>
-		<relativePath/>
-	</parent>
-	<groupId>cn.jlsxwkj</groupId>
-	<artifactId>ragchat</artifactId>
-	<name>ragchat</name>
-	<description>rag chat for Spring Boot</description>
-	<properties>
-		<java.version>17</java.version>
-		<spring-ai.version>1.0.0-M1</spring-ai.version>
-	</properties>
-	<dependencies>
-		<!--spring web-->
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-web</artifactId>
-		</dependency>
-		<!--spring ai-->
-		<dependency>
-			<groupId>org.springframework.ai</groupId>
-			<artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
-		</dependency>
-		<!--spring pgvector-->
-		<dependency>
-			<groupId>org.springframework.ai</groupId>
-			<artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
-		</dependency>
-		<!--pdf reader-->
-		<dependency>
-			<groupId>org.springframework.ai</groupId>
-			<artifactId>spring-ai-pdf-document-reader</artifactId>
-		</dependency>
-		<!--doc reader-->
-		<dependency>
-			<groupId>org.springframework.ai</groupId>
-			<artifactId>spring-ai-tika-document-reader</artifactId>
-		</dependency>
-		<!--json-->
-		<dependency>
-			<groupId>com.fasterxml.jackson.dataformat</groupId>
-			<artifactId>jackson-dataformat-avro</artifactId>
-		</dependency>
-		<!--aop-->
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-aop</artifactId>
-		</dependency>
-		<!--postgresql-->
-		<dependency>
-			<groupId>org.postgresql</groupId>
-			<artifactId>postgresql</artifactId>
-			<scope>runtime</scope>
-		</dependency>
-		<!--lombok-->
-		<dependency>
-			<groupId>org.projectlombok</groupId>
-			<artifactId>lombok</artifactId>
-		</dependency>
-		<!--configuration-->
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-configuration-processor</artifactId>
-			<optional>true</optional>
-		</dependency>
-		<!--鉴权-->
-		<dependency>
-			<groupId>cn.dev33</groupId>
-			<artifactId>sa-token-spring-boot3-starter</artifactId>
-			<version>1.38.0</version>
-		</dependency>
-		<!--解决 javax.annotation.meta.When.MAYBE 警告 (莫名其妙的警告)-->
-		<dependency>
-			<groupId>com.google.code.findbugs</groupId>
-			<artifactId>annotations</artifactId>
-			<version>3.0.1</version>
-		</dependency>
-		<!--mybatis-->
-		<dependency>
-			<groupId>org.mybatis.spring.boot</groupId>
-			<artifactId>mybatis-spring-boot-starter</artifactId>
-			<version>3.0.3</version>
-		</dependency>
-		<!--spring doc-->
-		<dependency>
-			<groupId>com.github.xiaoymin</groupId>
-			<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
-			<version>4.4.0</version>
-		</dependency>
-		<!--hutool-->
-		<dependency>
-			<groupId>cn.hutool</groupId>
-			<artifactId>hutool-all</artifactId>
-			<version>5.8.16</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-compress</artifactId>
-			<version>1.26.2</version>
-		</dependency>
-	</dependencies>
-	<dependencyManagement>
-		<dependencies>
-			<dependency>
-				<groupId>org.springframework.ai</groupId>
-				<artifactId>spring-ai-bom</artifactId>
-				<version>${spring-ai.version}</version>
-				<type>pom</type>
-				<scope>import</scope>
-			</dependency>
-		</dependencies>
-	</dependencyManagement>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>3.3.2</version>
+        <relativePath/>
+    </parent>
+    <groupId>cn.jlsxwkj</groupId>
+    <artifactId>ragchat</artifactId>
+    <name>ragchat</name>
+    <description>rag chat for Spring Boot</description>
+    <properties>
+        <java.version>17</java.version>
+        <spring-ai.version>1.0.0-M1</spring-ai.version>
+    </properties>
+    <dependencies>
+        <!--spring web-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <!--spring ai-->
+        <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
+        </dependency>
+        <!--spring pgvector-->
+        <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
+        </dependency>
+        <!--pdf reader-->
+        <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-pdf-document-reader</artifactId>
+        </dependency>
+        <!--doc reader-->
+        <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-tika-document-reader</artifactId>
+        </dependency>
+        <!--json-->
+        <dependency>
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
+            <artifactId>jackson-dataformat-avro</artifactId>
+        </dependency>
+        <!--aop-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+        <!--postgresql-->
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <!--lombok-->
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <!--configuration-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <!--鉴权-->
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-spring-boot3-starter</artifactId>
+            <version>1.38.0</version>
+        </dependency>
+        <!--解决 javax.annotation.meta.When.MAYBE 警告 (莫名其妙的警告)-->
+        <dependency>
+            <groupId>com.google.code.findbugs</groupId>
+            <artifactId>annotations</artifactId>
+            <version>3.0.1</version>
+        </dependency>
+        <!--mybatis-->
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>3.0.3</version>
+        </dependency>
+        <!--spring doc-->
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.4.0</version>
+        </dependency>
+        <!--hutool-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.16</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.26.2</version>
+        </dependency>
+    </dependencies>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.ai</groupId>
+                <artifactId>spring-ai-bom</artifactId>
+                <version>${spring-ai.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
 
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.springframework.boot</groupId>
-				<artifactId>spring-boot-maven-plugin</artifactId>
-			</plugin>
-		</plugins>
-	</build>
-	<repositories>
-		<repository>
-			<id>spring-milestones</id>
-			<name>Spring Milestones</name>
-			<url>https://repo.spring.io/milestone</url>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</repository>
-	</repositories>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <layout>ZIP</layout>
+                    <includes>
+                        <include>
+                            <groupId>nothing</groupId>
+                            <artifactId>nothing</artifactId>
+                        </include>
+                    </includes>
+                </configuration>
+            </plugin>
+        </plugins>
+        <!--打包后的文件名只带项目名,不带版本号-->
+        <finalName>${project.artifactId}</finalName>
+    </build>
+    <repositories>
+        <repository>
+            <id>spring-milestones</id>
+            <name>Spring Milestones</name>
+            <url>https://repo.spring.io/milestone</url>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
 </project>