maven如何添加jar包在maven中添加本地jar包

博客分类:
有关MAVEN仓库的理解参见:
MAVEN依赖关系中Scope的作用
Dependency Scope 在POM 4中,&dependency&中还引入了&scope&,它主要管理依赖的部署。目前依赖项的作用域&scope&可以使用5个值:
在定义项目的依赖项的时候,我们可以通过scope来指定该依赖项的作用范围。scope的取值有compile、runtime、test、provided、system和import。
compile:这是依赖项的默认作用范围,即当没有指定依赖项的scope时默认使用compile。compile范围内的依赖项在所有情况下都是有效的,包括运行、测试和编译时。
runtime:表示该依赖项只有在运行时才是需要的,在编译的时候不需要。这种类型的依赖项将在运行和test的类路径下可以访问。
test:表示该依赖项只对测试时有用,包括测试代码的编译和运行,对于正常的项目运行是没有影响的。
provided:表示该依赖项将由JDK或者运行容器在运行时提供,也就是说由Maven提供的该依赖项我们只有在编译和测试时才会用到,而在运行时将由JDK或者运行容器提供。
system:当scope为system时,表示该依赖项是我们自己提供的,不需要Maven到仓库里面去找。指定scope为system需要与另一个属性元素systemPath一起使用,它表示该依赖项在当前系统的位置,使用的是绝对路径。
POM文件里面可以引用一些内置属性(Maven预定义可以直接使用)
${basedir} 项目根目录
${version}表示项目版本;
${project.basedir}同${basedir};
${project.version}表示项目版本,与${version}相同;
${project.build.directory} 构建目录,缺省为target
${project.build.sourceEncoding}表示主源码的编码格式;
${project.build.sourceDirectory}表示主源码路径;
${project.build.finalName}表示输出文件名称;
${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes
如何在Maven项目中引入本地包呢?
比如我从其它项目打一个jar包,引入到现有项目中。
方法一:将待引入的包放在目录下如lib目录下,修改pom文件,加入依赖并且scope要设置为system
&dependencies&
&dependency&
&groupId&com.fbcds&/groupId&
&artifactId&fbcds&/artifactId&
&version&1.0&/version&
&scope&system&/scope&
&systemPath&${project.basedir}/lib/fbcds.jar&/systemPath&
&/dependency&
&/dependencies&
上面设置完成后,运行mvn package命令执行成功。但打出来的包里面不包含lib目录和fbcds.jar这个引用的包,即打出来的包不是可执行的jar。所以个人开发的话可以使用这种方式,如果团队开发请使用方法二。
方法二:将待引入的jar包安装到本地repository中
1、先把待引入的jar包放在一个目录下,需要改一下包名,如fbcds.jar修改成fbcds-1.0.jar,如F:\lib目录,在命令行CD到lib目录,执行以下命令:
mvn install:install-file -Dfile=fbcds-1.0.jar -DgroupId=fbcds -DartifactId=fbcds -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=ojdbc7-1.0.jar -DgroupId=ojdbc7 -DartifactId=ojdbc7 -Dversion=1.0 -Dpackaging=jar
2、修改项目pom文件加入包对应的依赖
&dependencies&
&dependency&
&groupId&log4j&/groupId&
&artifactId&log4j&/artifactId&
&version&1.2.17&/version&
&/dependency&
&dependency&
&groupId&fbcds&/groupId&
&artifactId&fbcds&/artifactId&
&version&1.0&/version&
&/dependency&
&dependency&
&groupId&ojdbc7&/groupId&
&artifactId&ojdbc7&/artifactId&
&version&1.0&/version&
&/dependency&
&/dependencies&
上面的fbcds和ojdbc7就是新加的引用包的依赖。
完成后,在本地仓库可看到对应的文件夹内容:
MAVEN如何打可执行的JAR包
前提条件:已成功将待引入的jar包安装到本地repository中
方法一、使用maven-shade-plugin插件打可执行的jar包
插件查找链接:
1、测试类代码
package com.lwf.
import java.sql.C
import java.sql.DriverM
import java.sql.ResultS
import java.sql.SQLE
import java.sql.S
import com.eclink.fbcis.store.StoreD
public class TestClass {
public static void main(String[] args) {
StoreDao a = new StoreDao();
System.out.println("------" + a.toString());
Connection con =
Statement st =
ResultSet rs =
String sql = "select * from temp_head where temp_no='C08015'";
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@//10.101.2.19:1521/pdbqmytcis","qmytcis","qmytcis123");
st = con.createStatement();
rs = st.executeQuery(sql);
if(rs.next()){
System.out.println(rs.getString("temp_no"));
} catch (Exception e) {
e.printStackTrace();
} finally{
rs.close();
st.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
上面类中引用到了fbcds和ojdbc7包的内容。
2、对应pom文件
&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&222&/groupId&
&artifactId&222&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&name&222&/name&
&dependencies&
&dependency&
&groupId&log4j&/groupId&
&artifactId&log4j&/artifactId&
&version&1.2.17&/version&
&/dependency&
&dependency&
&groupId&fbcds&/groupId&
&artifactId&fbcds&/artifactId&
&version&1.0&/version&
&/dependency&
&dependency&
&groupId&ojdbc7&/groupId&
&artifactId&ojdbc7&/artifactId&
&version&1.0&/version&
&/dependency&
&/dependencies&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-shade-plugin&/artifactId&
&version&2.4.3&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&shade&/goal&
&configuration&
&transformers&
&transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/transformer&
&/transformers&
&/configuration&
&/execution&
&/executions&
&/plugins&
&/project&
在eclipse中右键项目run as 选择Maven package,可看打包的target目录内容:
比较两个包内容:
执行包:cmd下
original-MavenPackage-0.0.1-SNAPSHOT.jar中没有主清单属性是执行不了的。
方法二、使用maven-assembly-plugin插件打可执行的jar包
测试类与方法一中一样,只是pom不一样,pom文件如下:
&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&com.lwf.MavenPackage&/groupId&
&artifactId&MavenPackage&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&name&MavenPackage&/name&
&dependencies&
&dependency&
&groupId&log4j&/groupId&
&artifactId&log4j&/artifactId&
&version&1.2.17&/version&
&/dependency&
&dependency&
&groupId&fbcds&/groupId&
&artifactId&fbcds&/artifactId&
&version&1.0&/version&
&/dependency&
&dependency&
&groupId&ojdbc7&/groupId&
&artifactId&ojdbc7&/artifactId&
&version&1.0&/version&
&/dependency&
&/dependencies&
&!-- 使用 maven-shade-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-shade-plugin&/artifactId&
&version&2.4.3&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&shade&/goal&
&configuration&
&transformers&
&transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/transformer&
&/transformers&
&/configuration&
&/execution&
&/executions&
&!-- 使用 maven-Assembly-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-assembly-plugin&/artifactId&
&version&2.6&/version&
&configuration&
&!-- get all project dependencies --&
&descriptorRefs&
&descriptorRef&jar-with-dependencies&/descriptorRef&
&/descriptorRefs&
&!-- MainClass in mainfest make a executable jar --&
&manifest&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/manifest&
&/archive&
&/configuration&
&executions&
&execution&
&id&make-assembly&/id&
&phase&package&/phase&
&goal&single&/goal&
&/execution&
&/executions&
&/plugins&
&/project&
修改完pom后,在eclipse中右键项目run as 选择Maven package,可看打包的target目录内容:
两个jar文件比较:
方法三、使用onejar-maven-plugin插件打可执行的jar包
测试类与方法一中一样,只是pom不一样,pom文件如下:
&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&com.lwf.MavenPackage&/groupId&
&artifactId&MavenPackage&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&name&MavenPackage&/name&
&dependencies&
&dependency&
&groupId&log4j&/groupId&
&artifactId&log4j&/artifactId&
&version&1.2.17&/version&
&/dependency&
&dependency&
&groupId&fbcds&/groupId&
&artifactId&fbcds&/artifactId&
&version&1.0&/version&
&/dependency&
&dependency&
&groupId&ojdbc7&/groupId&
&artifactId&ojdbc7&/artifactId&
&version&1.0&/version&
&/dependency&
&/dependencies&
&!-- 使用 maven-shade-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-shade-plugin&/artifactId&
&version&2.4.3&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&shade&/goal&
&configuration&
&transformers&
&transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/transformer&
&/transformers&
&/configuration&
&/execution&
&/executions&
&!-- 使用 maven-Assembly-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-assembly-plugin&/artifactId&
&version&2.6&/version&
&configuration&
&descriptorRefs&
&descriptorRef&jar-with-dependencies&/descriptorRef&
&/descriptorRefs&
&manifest&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/manifest&
&/archive&
&/configuration&
&executions&
&execution&
&id&make-assembly&/id&
&phase&package&/phase&
&goal&single&/goal&
&/execution&
&/executions&
&!-- 使用 onejar-maven-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-jar-plugin&/artifactId&
&configuration&
&manifest&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/manifest&
&/archive&
&/configuration&
&groupId&com.jolira&/groupId&
&artifactId&onejar-maven-plugin&/artifactId&
&version&1.4.4&/version&
&executions&
&execution&
&configuration&
&attachToBuild&true&/attachToBuild&
&classifier&onejar&/classifier&
&/configuration&
&goal&one-jar&/goal&
&/execution&
&/executions&
&/plugins&
&/project&
打包截图如下:
参见:http://www.mkyong.com/maven/maven-create-a-fat-jar-file-one-jar-example/
上文中因googlecode中已没有onejar-maven-plugin所以另请参见下文:
方法四:使用maven-jar-plugin和maven-dependency-plugin打可执行包,引用的包放包外面文件夹下
其他不变,pom文件如下
&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&com.lwf.MavenPackage&/groupId&
&artifactId&MavenPackage&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&name&MavenPackage&/name&
&dependencies&
&dependency&
&groupId&log4j&/groupId&
&artifactId&log4j&/artifactId&
&version&1.2.17&/version&
&/dependency&
&dependency&
&groupId&fbcds&/groupId&
&artifactId&fbcds&/artifactId&
&version&1.0&/version&
&/dependency&
&dependency&
&groupId&ojdbc7&/groupId&
&artifactId&ojdbc7&/artifactId&
&version&1.0&/version&
&/dependency&
&/dependencies&
&!-- 方法一:使用 maven-shade-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-shade-plugin&/artifactId&
&version&2.4.3&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&shade&/goal&
&configuration&
&transformers&
&transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/transformer&
&/transformers&
&/configuration&
&/execution&
&/executions&
&!-- 方法二:使用 maven-Assembly-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-assembly-plugin&/artifactId&
&version&2.6&/version&
&configuration&
&descriptorRefs&
&descriptorRef&jar-with-dependencies&/descriptorRef&
&/descriptorRefs&
&manifest&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/manifest&
&/archive&
&/configuration&
&executions&
&execution&
&id&make-assembly&/id&
&phase&package&/phase&
&goal&single&/goal&
&/execution&
&/executions&
&!-- 方法三:使用 onejar-maven-plugin插件打可执行包--&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-jar-plugin&/artifactId&
&configuration&
&manifest&
&mainClass&com.lwf.test.TestClass&/mainClass&
&/manifest&
&/archive&
&/configuration&
&groupId&com.jolira&/groupId&
&artifactId&onejar-maven-plugin&/artifactId&
&version&1.4.4&/version&
&executions&
&execution&
&configuration&
&attachToBuild&true&/attachToBuild&
&classifier&onejar&/classifier&
&/configuration&
&goal&one-jar&/goal&
&/execution&
&/executions&
&!-- 方法四:使用maven-jar-plugin和maven-dependency-plugin打可执行包,引用的包放包外面文件夹下 --&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-jar-plugin&/artifactId&
&configuration&
&excludes&
&exclude&**/log4j.properties&/exclude&
&/excludes&
&manifest&
&addClasspath&true&/addClasspath&
&mainClass&com.lwf.test.TestClass&/mainClass&
&classpathPrefix&lib/&/classpathPrefix&
&/manifest&
&/archive&
&/configuration&
&!-- Copy project dependency --&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-dependency-plugin&/artifactId&
&version&2.5.1&/version&
&executions&
&execution&
&id&copy-dependencies&/id&
&phase&package&/phase&
&goal&copy-dependencies&/goal&
&configuration&
&!-- exclude junit, we need runtime dependency only --&
&includeScope&runtime&/includeScope&
&outputDirectory&${project.build.directory}/lib/&/outputDirectory&
&/configuration&
&/execution&
&/executions&
&/plugins&
&/project&
可以看到依赖的包拷贝到了lib目录下,打的包里没有依赖包的信息,只是简单的包,不过Manifest文件class-path要包含引用名的路径
Manifest-Version: 1.0
Built-By: lweifeng
Build-Jdk: 1.7.0_17
Class-Path: lib/log4j-1.2.17.jar lib/fbcds-1.0.jar lib/ojdbc7-1.0.jar
Created-By: Apache Maven 3.3.9
Main-Class: com.lwf.test.TestClass
Archiver-Version: Plexus Archiver
在以上前三种插件打包方式中,maven-shade-plugin和maven-assembly-plugin采取的是将依赖包解压再一并打到新包中,这样依赖包可能存在冲突的时候,导致运行时可能出现未知问题,而onejar-maven-plugin打包是将依赖包自动归入lib目录,不解压原包,相当于在原包基础上加壳,这样可以避免冲突的发生。第四种方法即是我们原来ant打包所使用的方法。
下载次数: 31
浏览 28356
luweifeng1983
浏览: 845025 次
来自: 深圳
很好 感谢!
有用的,重启一下嘛。
设置了也不管用,怎么破呢?
锋子还有时间写博客,还是很闲哈!
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'如何向maven本地仓库添加jar包_百度知道
该问题可能描述不清,建议你
如何向maven本地仓库添加jar包
我有更好的答案
原则上Maven的设计是不需要这么做的,因为pom.xml中依赖的jar包会自动实现从中央仓库下载到本地仓库。但是公司设计了一个setting,如果本地仓库没有,就去setting指定的url中下载jar包,如果还没有就报错。考虑到setting中url的jar包比较老,如果需要用最新的,则需要将jar包手动下载到本地仓库。比如我下载了lucene-queryparser-4.6.1.jar怎么添加到本地仓库呢?步骤:1.cmd命令进入该jar包所在路径2.执行命令mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -Dversion=4.6.1 -Dpackaging=jar(不同的jar包相对应替换对应部分)另外我尝试了下面的方法,发现不行:直接写一个空的pom,里头包含对所需要jar包的依赖,通过这种方式希望将jar包下载到本地仓库。但是应用代码中没用到,maven命令没有下载这个jar包到本地仓库。补充,-DgroupId和-DartifactId的作用其实是指定了这个jar包的安装在repository的安装路径,只是用来告诉项目去这个路径下寻找这个名称的jar包。比如:mvn install:install-file -Dfile=freemarker-2.3.13.jar -DgroupId=freemarker -DartifactId=freemarker -Dversion=2.3.13 -Dpackaging=jar就是安装到了repository\freemarker\freemarker\2.3.13目录下,如果在dependency的依赖里也这么写的话,就可以到对应的目录去寻找。对于maven中存在classifier的,例如&dependency&
&groupId&org.apache.hadoop&/groupId&
&artifactId&hadoop-hdfs&/artifactId&
&version&2.2.0&/version&
&classifier&tests&/classifier&
&/dependency&就加一个-D参数就可以了,如下:mvn install:install-file -Dfile=hadoop-hdfs-2.2.0-tests.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-hdfs -Dversion=2.2.0 -Dclassifier=tests -Dpackaging=jar
采纳率:92%
来自团队:
为您推荐:
其他类似问题
maven的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。博客分类:
如何安装jar包到本地maven仓库呢?
使用如下命令即可:
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图形界面,专门干这个事:
源代码如下:
package com.yunma.
import java.awt.BorderL
import java.awt.EventQ
import javax.swing.JF
import javax.swing.JP
import javax.swing.JScrollP
import javax.swing.border.EmptyB
import java.awt.GridBagL
import javax.swing.JL
import java.awt.GridBagC
import javax.swing.JTextF
import java.awt.I
import javax.swing.JB
import com.cmd.dos.hw.util.CMDU
import com.string.widget.util.ValueW
import com.swing.component.AssistPopupTextA
import com.swing.dialog.DialogU
import java.awt.event.ActionL
import java.awt.event.ActionE
public class MavenTookitDialog extends JFrame {
private static final long serialVersionUID = -8465960L;
private JPanel contentP
private JTextField jarTextF
private JTextField groupIdTextField_1;
private JTextField artifactIdTextField_1;
private JTextField versionTextField_1;
private JTextField packagingTextField_1;
private JTextField textField_1;
public static final String MAVEN_INSTALL_JAR_CMD="mvn install:install-file
-DgroupId=%s
-DartifactId=%s -Dversion=%s -Dpackaging=%s";
private AssistPopupTextArea resultTextA
* Launch the application.
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
MavenTookitDialog frame = new MavenTookitDialog();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
* Create the frame.
public MavenTookitDialog() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("安装本地jar");
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[]{0, 0, 0};
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_contentPane.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
contentPane.setLayout(gbl_contentPane);
JLabel label = new JLabel("文件");
GridBagConstraints gbc_label = new GridBagConstraints();
gbc_label.insets = new Insets(0, 0, 5, 5);
gbc_label.anchor = GridBagConstraints.WEST;
gbc_label.gridx = 0;
gbc_label.gridy = 0;
contentPane.add(label, gbc_label);
jarTextField = new JTextField();
GridBagConstraints gbc_textField = new GridBagConstraints();
gbc_textField.insets = new Insets(0, 0, 5, 0);
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
gbc_textField.gridx = 1;
gbc_textField.gridy = 0;
contentPane.add(jarTextField, gbc_textField);
jarTextField.setColumns(10);
JLabel lblNewLabel = new JLabel("groupId");
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
gbc_lblNewLabel.gridx = 0;
gbc_lblNewLabel.gridy = 1;
contentPane.add(lblNewLabel, gbc_lblNewLabel);
groupIdTextField_1 = new JTextField();
GridBagConstraints gbc_groupIdTextField_1 = new GridBagConstraints();
gbc_groupIdTextField_1.insets = new Insets(0, 0, 5, 0);
gbc_groupIdTextField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_groupIdTextField_1.gridx = 1;
gbc_groupIdTextField_1.gridy = 1;
contentPane.add(groupIdTextField_1, gbc_groupIdTextField_1);
groupIdTextField_1.setColumns(10);
JLabel lblArtifactid = new JLabel("artifactId");
GridBagConstraints gbc_lblArtifactid = new GridBagConstraints();
gbc_lblArtifactid.anchor = GridBagConstraints.WEST;
gbc_lblArtifactid.insets = new Insets(0, 0, 5, 5);
gbc_lblArtifactid.gridx = 0;
gbc_lblArtifactid.gridy = 2;
contentPane.add(lblArtifactid, gbc_lblArtifactid);
artifactIdTextField_1 = new JTextField();
GridBagConstraints gbc_artifactIdTextField_1 = new GridBagConstraints();
gbc_artifactIdTextField_1.insets = new Insets(0, 0, 5, 0);
gbc_artifactIdTextField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_artifactIdTextField_1.gridx = 1;
gbc_artifactIdTextField_1.gridy = 2;
contentPane.add(artifactIdTextField_1, gbc_artifactIdTextField_1);
artifactIdTextField_1.setColumns(10);
JLabel lblVersion = new JLabel("version");
GridBagConstraints gbc_lblVersion = new GridBagConstraints();
gbc_lblVersion.anchor = GridBagConstraints.WEST;
gbc_lblVersion.insets = new Insets(0, 0, 5, 5);
gbc_lblVersion.gridx = 0;
gbc_lblVersion.gridy = 3;
contentPane.add(lblVersion, gbc_lblVersion);
versionTextField_1 = new JTextField();
GridBagConstraints gbc_versionTextField_1 = new GridBagConstraints();
gbc_versionTextField_1.insets = new Insets(0, 0, 5, 0);
gbc_versionTextField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_versionTextField_1.gridx = 1;
gbc_versionTextField_1.gridy = 3;
contentPane.add(versionTextField_1, gbc_versionTextField_1);
versionTextField_1.setColumns(10);
JLabel lblPackaging = new JLabel("packaging");
GridBagConstraints gbc_lblPackaging = new GridBagConstraints();
gbc_lblPackaging.anchor = GridBagConstraints.WEST;
gbc_lblPackaging.insets = new Insets(0, 0, 5, 5);
gbc_lblPackaging.gridx = 0;
gbc_lblPackaging.gridy = 4;
contentPane.add(lblPackaging, gbc_lblPackaging);
packagingTextField_1 = new JTextField("jar");
GridBagConstraints gbc_packagingTextField_1 = new GridBagConstraints();
gbc_packagingTextField_1.insets = new Insets(0, 0, 5, 0);
gbc_packagingTextField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_packagingTextField_1.gridx = 1;
gbc_packagingTextField_1.gridy = 4;
contentPane.add(packagingTextField_1, gbc_packagingTextField_1);
packagingTextField_1.setColumns(10);
/*JLabel label_1 = new JLabel("预留");
GridBagConstraints gbc_label_1 = new GridBagConstraints();
gbc_label_1.anchor = GridBagConstraints.WEST;
gbc_label_1.insets = new Insets(0, 0, 5, 5);
gbc_label_1.gridx = 0;
gbc_label_1.gridy = 5;
contentPane.add(label_1, gbc_label_1);
textField_1 = new JTextField();
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
gbc_textField_1.insets = new Insets(0, 0, 5, 0);
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_textField_1.gridx = 1;
gbc_textField_1.gridy = 5;
contentPane.add(textField_1, gbc_textField_1);
textField_1.setColumns(10);*/
JPanel panel = new JPanel();
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.insets = new Insets(0, 0, 5, 0);
gbc_panel.gridwidth = 2;
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.gridx = 0;
gbc_panel.gridy = 6;
contentPane.add(panel, gbc_panel);
JButton button_1 = new JButton("安装");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!DialogUtil.verifyTFAndExist(jarTextField, "jar 文件")){
String jarPath=jarTextField.getText();
jarPath=jarPath.replace("\\", "/");
if(!DialogUtil.verifyTFEmpty(groupIdTextField_1, "groupId")){
if(!DialogUtil.verifyTFEmpty(artifactIdTextField_1, "artifactId")){
if(!DialogUtil.verifyTFEmpty(versionTextField_1, "version")){
if(!DialogUtil.verifyTFEmpty(packagingTextField_1, "packaging")){
String groupId=groupIdTextField_1.getText();
String artifactId=artifactIdTextField_1.getText();
String version=versionTextField_1.getText();
String packaging=packagingTextField_1.getText();
if(ValueWidget.isNullOrEmpty(packaging)){
packaging="jar";
String cmd=String.format(MAVEN_INSTALL_JAR_CMD, jarPath,groupId,artifactId,version,packaging);
System.out.println(cmd);
CMDUtil.getResult4cmd(cmd);
resultTextArea.setText(cmd);
panel.add(button_1);
JPanel panel_1 = new JPanel();
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
gbc_panel_1.gridwidth = 2;
gbc_panel_1.fill = GridBagConstraints.BOTH;
gbc_panel_1.gridx = 0;
gbc_panel_1.gridy = 7;
contentPane.add(panel_1, gbc_panel_1);
panel_1.setLayout(new BorderLayout(0, 0));
resultTextArea=new AssistPopupTextArea();
JScrollPane js=new JScrollPane(resultTextArea);
panel_1.add(js);
CMDUtil.getResult4cmd的实现见
http://pan.baidu.com/s/1pJAaOif
中的com.cmd.dos.hw.util.CMDUtil
浏览: 3204869 次
来自: 北京
6ee55ec8ed9fff ...
6ee55ec8ed9fff ...
gmxy 写道a 写道指正一个错误:BigI ...
a 写道指正一个错误:BigInteger
写的十分详细我反复看了好几遍很难得把知识讲的如此详尽 表结构都 ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'}

我要回帖

更多关于 maven如何添加jar包 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信