安装jar包到本地maven仓库-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

安装jar包到本地maven仓库

简介:

如何安装jar包到本地maven仓库呢?

使用如下命令即可:

Java代码  收藏代码
  1. mvn install:install-file  -Dfile=e:\tmp\hijson\HiJson.jar  -DgroupId=com.kunlunsoft5  -DartifactId=Hijson -Dversion=1.0.0 -Dpackaging=jar  



 

 参数说明:

-Dfile :指定jar路径

-DgroupId :指定jar包的groupId

-DartifactId :指定jar包的artifactId

 

我写了一个Java swing图形界面,专门干这个事:

 

源代码如下:

Java代码  收藏代码
  1. package com.yunma.dialog;  
  2.   
  3. import java.awt.BorderLayout;  
  4. import java.awt.EventQueue;  
  5.   
  6. import javax.swing.JFrame;  
  7. import javax.swing.JPanel;  
  8. import javax.swing.JScrollPane;  
  9. import javax.swing.border.EmptyBorder;  
  10.   
  11. import java.awt.GridBagLayout;  
  12.   
  13. import javax.swing.JLabel;  
  14.   
  15. import java.awt.GridBagConstraints;  
  16.   
  17. import javax.swing.JTextField;  
  18.   
  19. import java.awt.Insets;  
  20.   
  21. import javax.swing.JButton;  
  22.   
  23. import com.cmd.dos.hw.util.CMDUtil;  
  24. import com.string.widget.util.ValueWidget;  
  25. import com.swing.component.AssistPopupTextArea;  
  26. import com.swing.dialog.DialogUtil;  
  27.   
  28. import java.awt.event.ActionListener;  
  29. import java.awt.event.ActionEvent;  
  30.   
  31. public class MavenTookitDialog extends JFrame {  
  32.   
  33.     private static final long serialVersionUID = -3076948674378465960L;  
  34.     private JPanel contentPane;  
  35.     private JTextField jarTextField;  
  36.     private JTextField groupIdTextField_1;  
  37.     private JTextField artifactIdTextField_1;  
  38.     private JTextField versionTextField_1;  
  39.     private JTextField packagingTextField_1;  
  40.     private JTextField textField_1;  
  41.     public static final String MAVEN_INSTALL_JAR_CMD="mvn install:install-file  -Dfile=%s  -DgroupId=%s  -DartifactId=%s -Dversion=%s -Dpackaging=%s";  
  42.     private AssistPopupTextArea resultTextArea;  
  43.   
  44.     /** 
  45.      * Launch the application. 
  46.      */  
  47.     public static void main(String[] args) {  
  48.         EventQueue.invokeLater(new Runnable() {  
  49.             public void run() {  
  50.                 try {  
  51.                     MavenTookitDialog frame = new MavenTookitDialog();  
  52.                     frame.setVisible(true);  
  53.                 } catch (Exception e) {  
  54.                     e.printStackTrace();  
  55.                 }  
  56.             }  
  57.         });  
  58.     }  
  59.   
  60.     /** 
  61.      * Create the frame. 
  62.      */  
  63.     public MavenTookitDialog() {  
  64.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  65.         setTitle("安装本地jar");  
  66.         setBounds(100100450300);  
  67.         contentPane = new JPanel();  
  68.         contentPane.setBorder(new EmptyBorder(5555));  
  69.         setContentPane(contentPane);  
  70.         GridBagLayout gbl_contentPane = new GridBagLayout();  
  71.         gbl_contentPane.columnWidths = new int[]{000};  
  72.         gbl_contentPane.rowHeights = new int[]{000000000};  
  73.         gbl_contentPane.columnWeights = new double[]{0.01.0, Double.MIN_VALUE};  
  74.         gbl_contentPane.rowWeights = new double[]{0.00.00.00.00.00.00.01.0, Double.MIN_VALUE};  
  75.         contentPane.setLayout(gbl_contentPane);  
  76.           
  77.         JLabel label = new JLabel("文件");  
  78.         GridBagConstraints gbc_label = new GridBagConstraints();  
  79.         gbc_label.insets = new Insets(0055);  
  80.         gbc_label.anchor = GridBagConstraints.WEST;  
  81.         gbc_label.gridx = 0;  
  82.         gbc_label.gridy = 0;  
  83.         contentPane.add(label, gbc_label);  
  84.           
  85.         jarTextField = new JTextField();  
  86.         GridBagConstraints gbc_textField = new GridBagConstraints();  
  87.         gbc_textField.insets = new Insets(0050);  
  88.         gbc_textField.fill = GridBagConstraints.HORIZONTAL;  
  89.         gbc_textField.gridx = 1;  
  90.         gbc_textField.gridy = 0;  
  91.         contentPane.add(jarTextField, gbc_textField);  
  92.         jarTextField.setColumns(10);  
  93.           
  94.         JLabel lblNewLabel = new JLabel("groupId");  
  95.         GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();  
  96.         gbc_lblNewLabel.anchor = GridBagConstraints.WEST;  
  97.         gbc_lblNewLabel.insets = new Insets(0055);  
  98.         gbc_lblNewLabel.gridx = 0;  
  99.         gbc_lblNewLabel.gridy = 1;  
  100.         contentPane.add(lblNewLabel, gbc_lblNewLabel);  
  101.           
  102.         groupIdTextField_1 = new JTextField();  
  103.         GridBagConstraints gbc_groupIdTextField_1 = new GridBagConstraints();  
  104.         gbc_groupIdTextField_1.insets = new Insets(0050);  
  105.         gbc_groupIdTextField_1.fill = GridBagConstraints.HORIZONTAL;  
  106.         gbc_groupIdTextField_1.gridx = 1;  
  107.         gbc_groupIdTextField_1.gridy = 1;  
  108.         contentPane.add(groupIdTextField_1, gbc_groupIdTextField_1);  
  109.         groupIdTextField_1.setColumns(10);  
  110.           
  111.         JLabel lblArtifactid = new JLabel("artifactId");  
  112.         GridBagConstraints gbc_lblArtifactid = new GridBagConstraints();  
  113.         gbc_lblArtifactid.anchor = GridBagConstraints.WEST;  
  114.         gbc_lblArtifactid.insets = new Insets(0055);  
  115.         gbc_lblArtifactid.gridx = 0;  
  116.         gbc_lblArtifactid.gridy = 2;  
  117.         contentPane.add(lblArtifactid, gbc_lblArtifactid);  
  118.           
  119.         artifactIdTextField_1 = new JTextField();  
  120.         GridBagConstraints gbc_artifactIdTextField_1 = new GridBagConstraints();  
  121.         gbc_artifactIdTextField_1.insets = new Insets(0050);  
  122.         gbc_artifactIdTextField_1.fill = GridBagConstraints.HORIZONTAL;  
  123.         gbc_artifactIdTextField_1.gridx = 1;  
  124.         gbc_artifactIdTextField_1.gridy = 2;  
  125.         contentPane.add(artifactIdTextField_1, gbc_artifactIdTextField_1);  
  126.         artifactIdTextField_1.setColumns(10);  
  127.           
  128.         JLabel lblVersion = new JLabel("version");  
  129.         GridBagConstraints gbc_lblVersion = new GridBagConstraints();  
  130.         gbc_lblVersion.anchor = GridBagConstraints.WEST;  
  131.         gbc_lblVersion.insets = new Insets(0055);  
  132.         gbc_lblVersion.gridx = 0;  
  133.         gbc_lblVersion.gridy = 3;  
  134.         contentPane.add(lblVersion, gbc_lblVersion);  
  135.           
  136.         versionTextField_1 = new JTextField();  
  137.         GridBagConstraints gbc_versionTextField_1 = new GridBagConstraints();  
  138.         gbc_versionTextField_1.insets = new Insets(0050);  
  139.         gbc_versionTextField_1.fill = GridBagConstraints.HORIZONTAL;  
  140.         gbc_versionTextField_1.gridx = 1;  
  141.         gbc_versionTextField_1.gridy = 3;  
  142.         contentPane.add(versionTextField_1, gbc_versionTextField_1);  
  143.         versionTextField_1.setColumns(10);  
  144.           
  145.         JLabel lblPackaging = new JLabel("packaging");  
  146.         GridBagConstraints gbc_lblPackaging = new GridBagConstraints();  
  147.         gbc_lblPackaging.anchor = GridBagConstraints.WEST;  
  148.         gbc_lblPackaging.insets = new Insets(0055);  
  149.         gbc_lblPackaging.gridx = 0;  
  150.         gbc_lblPackaging.gridy = 4;  
  151.         contentPane.add(lblPackaging, gbc_lblPackaging);  
  152.           
  153.         packagingTextField_1 = new JTextField("jar");  
  154.         GridBagConstraints gbc_packagingTextField_1 = new GridBagConstraints();  
  155.         gbc_packagingTextField_1.insets = new Insets(0050);  
  156.         gbc_packagingTextField_1.fill = GridBagConstraints.HORIZONTAL;  
  157.         gbc_packagingTextField_1.gridx = 1;  
  158.         gbc_packagingTextField_1.gridy = 4;  
  159.         contentPane.add(packagingTextField_1, gbc_packagingTextField_1);  
  160.         packagingTextField_1.setColumns(10);  
  161.           
  162.         /*JLabel label_1 = new JLabel("预留"); 
  163.         GridBagConstraints gbc_label_1 = new GridBagConstraints(); 
  164.         gbc_label_1.anchor = GridBagConstraints.WEST; 
  165.         gbc_label_1.insets = new Insets(0, 0, 5, 5); 
  166.         gbc_label_1.gridx = 0; 
  167.         gbc_label_1.gridy = 5; 
  168.         contentPane.add(label_1, gbc_label_1); 
  169.          
  170.         textField_1 = new JTextField(); 
  171.         GridBagConstraints gbc_textField_1 = new GridBagConstraints(); 
  172.         gbc_textField_1.insets = new Insets(0, 0, 5, 0); 
  173.         gbc_textField_1.fill = GridBagConstraints.HORIZONTAL; 
  174.         gbc_textField_1.gridx = 1; 
  175.         gbc_textField_1.gridy = 5; 
  176.         contentPane.add(textField_1, gbc_textField_1); 
  177.         textField_1.setColumns(10);*/  
  178.           
  179.         JPanel panel = new JPanel();  
  180.         GridBagConstraints gbc_panel = new GridBagConstraints();  
  181.         gbc_panel.insets = new Insets(0050);  
  182.         gbc_panel.gridwidth = 2;  
  183.         gbc_panel.fill = GridBagConstraints.BOTH;  
  184.         gbc_panel.gridx = 0;  
  185.         gbc_panel.gridy = 6;  
  186.         contentPane.add(panel, gbc_panel);  
  187.           
  188.         JButton button_1 = new JButton("安装");  
  189.         button_1.addActionListener(new ActionListener() {  
  190.             public void actionPerformed(ActionEvent e) {  
  191.                 if(!DialogUtil.verifyTFAndExist(jarTextField, "jar 文件")){  
  192.                     return;  
  193.                 }  
  194.                 String jarPath=jarTextField.getText();  
  195.                 jarPath=jarPath.replace("\\", "/");  
  196.                 if(!DialogUtil.verifyTFEmpty(groupIdTextField_1, "groupId")){  
  197.                     return;  
  198.                 }  
  199.                 if(!DialogUtil.verifyTFEmpty(artifactIdTextField_1, "artifactId")){  
  200.                     return;  
  201.                 }  
  202.                 if(!DialogUtil.verifyTFEmpty(versionTextField_1, "version")){  
  203.                     return;  
  204.                 }  
  205.                 if(!DialogUtil.verifyTFEmpty(packagingTextField_1, "packaging")){  
  206.                     return;  
  207.                 }  
  208.                 String groupId=groupIdTextField_1.getText();  
  209.                 String artifactId=artifactIdTextField_1.getText();  
  210.                 String version=versionTextField_1.getText();  
  211.                 String packaging=packagingTextField_1.getText();  
  212.                 if(ValueWidget.isNullOrEmpty(packaging)){  
  213.                     packaging="jar";  
  214.                 }  
  215.                 String cmd=String.format(MAVEN_INSTALL_JAR_CMD, jarPath,groupId,artifactId,version,packaging);  
  216. //              System.out.println(cmd);  
  217.                 CMDUtil.getResult4cmd(cmd);  
  218.                 resultTextArea.setText(cmd);  
  219.                   
  220.             }  
  221.         });  
  222.         panel.add(button_1);  
  223.           
  224.         JPanel panel_1 = new JPanel();  
  225.         GridBagConstraints gbc_panel_1 = new GridBagConstraints();  
  226.         gbc_panel_1.gridwidth = 2;  
  227.         gbc_panel_1.fill = GridBagConstraints.BOTH;  
  228.         gbc_panel_1.gridx = 0;  
  229.         gbc_panel_1.gridy = 7;  
  230.         contentPane.add(panel_1, gbc_panel_1);  
  231.         panel_1.setLayout(new BorderLayout(00));  
  232.         resultTextArea=new AssistPopupTextArea();  
  233.         JScrollPane js=new JScrollPane(resultTextArea);  
  234.         panel_1.add(js);  
  235.     }  
  236.   
  237. }  

 CMDUtil.getResult4cmd的实现见

http://pan.baidu.com/s/1pJAaOif

中的com.cmd.dos.hw.util.CMDUtil

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: