聊天网站开发,网站策划方案800字,网站建设总结ppt,网站开发net教程工作中有时候偶尔写一些工具类、小程序#xff0c;可是java程序员制作一个可运行jar实在折腾#xff0c;利用idea开发环境#xff0c;可以快速打包自己的可运行jar。具体怎么操作呢#xff1f;
创建一个空白的java项目并完成自己的程序开发 完成java代码#xff1a;
/**…工作中有时候偶尔写一些工具类、小程序可是java程序员制作一个可运行jar实在折腾利用idea开发环境可以快速打包自己的可运行jar。具体怎么操作呢
创建一个空白的java项目并完成自己的程序开发 完成java代码
/*** 测试窗口* author binbin* date 2023/9/27 10:29*/
public class InfoFrame extends JFrame {public InfoFrame() {setTitle(System Information);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(300, 200);//居中显示Dimension screenSize Toolkit.getDefaultToolkit().getScreenSize();setLocation((screenSize.width - getWidth())/2, (screenSize.height - getHeight())/2);//初始化菜单JMenuBar bar new JMenuBar();JMenu menu new JMenu(帮助);JMenuItem exitItem new JMenuItem(退出);exitItem.addActionListener(e - {System.exit(0);});menu.add(exitItem);bar.add(menu);setJMenuBar(bar);//初始化系统信息JTextArea infoTextArea new JTextArea(6, 10);infoTextArea.setText(getSystemInfo());infoTextArea.setEditable(false);add(new JScrollPane(infoTextArea));}private String getSystemInfo() {StringBuffer b new StringBuffer();b.append(系统系统).append(System.getProperty(os.name)).append(\r\n);b.append(系统版本).append(System.getProperty(os.version)).append(\r\n);b.append(系统架构).append(System.getProperty(os.arch)).append(\r\n);b.append(用户名称).append(System.getProperty(user.name)).append(\r\n);b.append(用户主目录).append(System.getProperty(user.home)).append(\r\n);b.append(当前工作目录).append(System.getProperty(user.dir)).append(\r\n);return b.toString();}
}
public class App
{public static void main( String[] args ){EventQueue.invokeLater(() - {new InfoFrame().setVisible(true);});}
}代码结构如下
引入maven-assembly-plugin插件打包
?xml version1.0 encodingUTF-8?project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.hbin/groupIdartifactIdinfo/artifactIdversion1.0-SNAPSHOT/versionnameinfo/nameurlwww.binbin.org/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingmaven.compiler.source1.8/maven.compiler.sourcemaven.compiler.target1.8/maven.compiler.target/propertiesdependenciesdependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.11/versionscopetest/scope/dependency/dependenciesbuildplugins!-- 使用maven-assembly-plugin插件打包 --plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-assembly-plugin/artifactIdversion3.2.0/versionconfigurationarchivemanifest!--主类 --mainClassorg.hbin.App/mainClass/manifest/archivedescriptorRefs!-- 可执行jar名称结尾--descriptorRefjar-with-dependencies/descriptorRef/descriptorRefs/configurationexecutionsexecutionidmake-assembly/idphasepackage/phasegoalsgoalsingle/goal/goals/execution/executions/plugin/plugins/build
/project执行maven package
执行maven package命令target目录将生成一个以jar-with-dependencies结尾的可直接执行jar。 运行命令 java -jar info-1.0-SNAPSHOT-jar-with-dependencies.jar文档包和源码包
!--生成doc jar包--
plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-javadoc-plugin/artifactIdexecutionsexecutionidattach-javadocs/idgoalsgoaljar/goal/goals!-- 不让像Param 这种后面没写值的东西 报错。--configurationadditionalJOption-Xdoclint:none/additionalJOption/configuration/execution/executions
/plugin!--生成源码jar包--
plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-source-plugin/artifactIdexecutionsexecutionidattach-sources/idgoalsgoaljar/goal/goals/execution/executions
/plugin下次再有测试、运营或者其他部门的同事找你做工具知道怎样快速制作可执行jar了吧