idea swing gui设计后用mvn打包的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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>TestPub</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.17.0</version> </dependency> <dependency> <groupId>de.ruedigermoeller</groupId> <artifactId>fst</artifactId> <version>2.57</version> </dependency> <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>com.intellij</groupId> <artifactId>forms_rt</artifactId> <version>7.0.3</version> </dependency> </dependencies> <!-- 方式一--> <!-- <build>--> <!-- <plugins>--> <!-- <plugin>--> <!-- <groupId>org.apache.maven.plugins</groupId>--> <!-- <artifactId>maven-assembly-plugin</artifactId>--> <!-- <version>2.4.1</version>--> <!-- <configuration>--> <!-- <appendAssemblyId>false</appendAssemblyId>--> <!-- <finalName>xxx-xxx</finalName>--> <!-- <descriptorRefs>--> <!-- <!–将依赖的jar包中的class文件打进生成的jar包–>--> <!-- <defcriptorRef>jar-with-dependencies</defcriptorRef>--> <!-- </descriptorRefs>--> <!-- <archive>--> <!-- <manifest>--> <!-- <addClasspath>true</addClasspath>--> <!-- <!–指定入口函数–>--> <!-- <mainClass>com.test.myFram</mainClass>--> <!-- </manifest>--> <!-- </archive>--> <!-- </configuration>--> <!-- <executions>--> <!-- <execution>--> <!-- <id>make-assembly</id>--> <!-- <phase>package</phase>--> <!-- <goals>--> <!-- <goal>assembly</goal>--> <!-- </goals>--> <!-- </execution>--> <!-- </executions>--> <!-- </plugin>--> <!-- <!– IDEA Gui Designer Plugin –>--> <!-- <plugin>--> <!-- <groupId>org.codehaus.mojo</groupId>--> <!-- <artifactId>ideauidesigner-maven-plugin</artifactId>--> <!-- <version>1.0-beta-1</version>--> <!-- <executions>--> <!-- <execution>--> <!-- <goals>--> <!-- <goal>javac2</goal>--> <!-- </goals>--> <!-- </execution>--> <!-- </executions>--> <!-- <configuration>--> <!-- <fork>true</fork>--> <!-- <debug>true</debug>--> <!-- <failOnError>true</failOnError>--> <!-- </configuration>--> <!-- </plugin>--> <!-- </plugins>--> <!-- </build>--> <!-- 方式二--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <!-- 生成的jar中,包含pom.xml和pom.properties这两个文件 --> <!-- <addMavenDescriptor>true</addMavenDescriptor>--> <!-- 生成MANIFEST.MF的设置 --> <manifest> <!--这个属性特别关键,如果没有这个属性,有时候我们引用的包maven库 下面可能会有多个包,并且只有一个是正确的,其余的可能是带时间戳的, 此时会在classpath下面把那个带时间戳的给添加上去,然后我们 在依赖打包的时候,打的是正确的,所以两头会对不上,报错。--> <useUniqueVersions>false</useUniqueVersions> <!-- 为依赖包添加路径, 这些路径会写在MANIFEST文件的Class-Path下 --> <addClasspath>true</addClasspath> <!-- 这个jar所依赖的jar包添加classPath的时候的前缀,如果这个 jar本身和依赖包在同一级目录,则不需要添加--> <classpathPrefix>lib/</classpathPrefix> <!-- jar启动入口类--> <mainClass>com.test.myFram</mainClass> </manifest> <!-- <manifestEntries>--> <!-- <!– 在Class-Path下添加配置文件的路径 –>--> <!-- <!– <Class-Path>../config</Class-Path>–>--> <!-- <!– 假如这个项目可能要引入一些外部资源,但是你打包的时候并不想把--> <!-- 这些资源文件打进包里面,这个时候你必须在这边额外指定一些这些资源--> <!-- 文件的路径,这个位置指定的话,要根据你预期的这些位置去设置,我这边--> <!-- 所有jar都在lib下,资源文件都在config下,lib和config是同级的 –>--> <!-- <!– 同时还需要注意另外一个问题,假如你的pom文件里面配置了--> <!-- <scope>system</scope>,就是你依赖是你本地的资源,这个时候使用--> <!-- 这个插件,classPath里面是不会添加,所以你得手动把这个依赖添加进--> <!-- 这个地方,用空格隔开就行–>--> <!-- <Class-Path></Class-Path>--> <!-- </manifestEntries>--> </archive> <!-- jar包的位置--> <outputDirectory>${project.build.directory}/</outputDirectory> <includes> <!-- 打jar包时,只打包class文件 --> <!-- 有时候可能需要一些其他文件,这边可以配置,包括剔除的文件等等--> <include>**/*.class</include> </includes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy</id> <phase>package</phase><!--阶段--> <goals> <goal>copy-dependencies</goal><!--目标--> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <!--已存在的Release版本不重复copy--> <overWriteReleases>false</overWriteReleases> <!--已存在的SnapShot版本不重复copy--> <overWriteSnapshots>false</overWriteSnapshots> <!--不存在或者有更新版本的依赖才copy--> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <!-- IDEA Gui Designer Plugin --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>ideauidesigner-maven-plugin</artifactId> <version>1.0-beta-1</version> <executions> <execution> <goals> <goal>javac2</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <debug>true</debug> <failOnError>true</failOnError> </configuration> </plugin> </plugins> </build> </project>
方式一和方式二打包都是可行的,没什么区别。
idea下的swing设计的maven打包需要引入依赖
<dependency> <groupId>com.intellij</groupId> <artifactId>forms_rt</artifactId> <version>7.0.3</version> </dependency>
和使用插件
<!-- IDEA Gui Designer Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
jar包的下载都可以去如下地址查询:https://mvnrepository.com/search?q=
注意:当maven时,clean->compile都没问题时,并不代表package阶段会通过,因为有些写法,swing打包时不通过
例如:list.forEach(this::deailFunction);会报错如下

修改为传统方式即可:
for(int i=0;i<list.size();i++){
deailFunction(list.get(i));
}
例如:Supplier<LoggingHandler> func = ()-> new LoggingHandler(LogLevel.TRACE);这种写法同样会报错如下

也是修改为传统方式即可:
private static class LogingHandler implements Supplier<LoggingHandler>{
@Override
public LoggingHandler get() {
return new LoggingHandler(LogLevel.TRACE);
}
}
stream流操作也不支持打包
具体原因尚未找到具体说明,但是一些sdk新得语法糖可能在swing打包时不支持,导致报错。若是哪位朋友有完善得信息,请赐教!
目前处理方法是将核心逻辑模块与打包swing模块分开,这样核心逻辑模块就不受限制了。只需要注意swing打包模块得代码就行了
其他类型参考资料:
java – IntelliJ GUI Designer Maven可执行JAR导出: https://www.icode9.com/content-1-474354.html
IntelliJ基于Grandle通过GUI Form创建Swing项目的过程:https://blog.csdn.net/qq_35205516/article/details/103855901
分类:
java
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!