aar上传maven库工具
需求:本地aar文件上传到maven库
参考我之前的博客gradle上传本地文件到远程maven库(nexus服务器)
下面是java图形化工具代码
package com.jinkejoy.build_aar; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; public class UploadAarFile { private JFrame jFrame; private JTextField aar_path; private JButton aarPath_button; private File aar_File; private JTextField main_path; private JButton main_button; private File main_File; private JTextField groupId; private JTextField artifactId; private JTextField version; private JButton upload; public static void main(String[] args) { new UploadAarFile(); } public UploadAarFile() { openFileWindow(); } private void openFileWindow() { jFrame = new JFrame(); jFrame.setTitle("将aar上传到maven库"); jFrame.setBounds(500, 500, 700, 160); jFrame.setVisible(true); FlowLayout layout = new FlowLayout(); layout.setAlignment(FlowLayout.LEFT); //选择aar文件 JLabel filePath_label = new JLabel("aar本地路径:"); aar_path = new JTextField(48); aarPath_button = new JButton("浏览"); //前缀包名 JLabel groupId_label = new JLabel("前缀包名:"); groupId = new JTextField(25); //aar名 JLabel aar_label = new JLabel("aar文件名:"); artifactId = new JTextField(25); //版本 JLabel version_label = new JLabel("aar版本号:"); version = new JTextField(25); //母包 JLabel main_label = new JLabel("母包路径:"); main_path = new JTextField(50); main_button = new JButton("浏览"); //上传 upload = new JButton("上传"); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setLayout(layout); jFrame.setResizable(false); jFrame.add(main_label); jFrame.add(main_path); jFrame.add(main_button); jFrame.add(filePath_label); jFrame.add(aar_path); jFrame.add(aarPath_button); jFrame.add(groupId_label); jFrame.add(groupId); jFrame.add(aar_label); jFrame.add(artifactId); jFrame.add(version_label); jFrame.add(version); jFrame.add(upload); findAarFile(); findMainFile(); uploadAar(); } private void findMainFile() { main_button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.showDialog(new JLabel(), "选择"); main_File = chooser.getSelectedFile(); main_path.setText(main_File.getAbsolutePath().toString()); } }); } private void findAarFile() { aarPath_button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.showDialog(new JLabel(), "选择"); aar_File = chooser.getSelectedFile(); aar_path.setText(aar_File.getAbsolutePath().toString()); } }); } private void uploadAar() { upload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { uploadAarImpl(); } }); } private void uploadAarImpl() { if (checkInput()) return; cachePath(); gradleUpload(); } private void cachePath() { String cache = "mainPath=" + main_path.getText().toString().replace("\\", "\\\\") + "\n" + "aarPath=" + aar_path.getText().toString().replace("\\", "\\\\") + "\n" + "groupId=" + groupId.getText().toString().replace("\\", "\\\\") + "\n" + "artifactId=" + artifactId.getText().toString().replace("\\", "\\\\") + "\n" + "version=" + version.getText().toString().replace("\\", "\\\\"); File cacheFile = new File(main_path.getText().toString() + "/aarParam.properties"); if (!cacheFile.exists()) { try { cacheFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { FileOutputStream fop = new FileOutputStream(cacheFile); fop.write(cache.getBytes()); fop.flush(); fop.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private void gradleUpload() { String command = "cmd /c start gradlew clean uploadArchives"; File cmdPath = new File(main_path.getText().toString()); Runtime runtime = Runtime.getRuntime(); try { Process process = runtime.exec(command, null, cmdPath); } catch (IOException e) { e.printStackTrace(); } } private boolean checkInput() { if ("".equals(aar_path.getText().toString())) { JOptionPane.showMessageDialog(jFrame, "请输入aar文件路径"); return true; } if ("".equals(main_path.getText().toString())) { JOptionPane.showMessageDialog(jFrame, "请输入母包路径"); return true; } if ("".equals(groupId.getText().toString())) { JOptionPane.showMessageDialog(jFrame, "请输入前缀包名"); return true; } if ("".equals(artifactId.getText().toString())) { JOptionPane.showMessageDialog(jFrame, "请输入aar名称"); return true; } if ("".equals(version.getText().toString())) { JOptionPane.showMessageDialog(jFrame, "请输入aar版本号"); return true; } return false; } }
jar包打成可运行程序参考android studio打可执行jar包
效果图
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2016-06-20 【设计模式】状态模式
2016-06-20 【设计模式】观察者模式
2016-06-20 【设计模式】备忘录模式