大数据爬虫基础(三) MAVEN的安装配置和使用(上)

环境:

ubuntu server 14.04.04 amd64 jdk1.8

1. 安装:

http://www.jikexueyuan.com/course/571_4.html?ss=1
下载、解压、M2_HOME、PATH
mvn -version


2. 使用
http://www.jikexueyuan.com/course/maven/


2.1 java代码
package com.jikexueyuan
public class App{
    public static void main(String[] args){
        System.out.println("Hello World!");
    }
}


2.2 构建maven项目骨架
root@spark:~# mvn archetype:generate
结果:
1606: remote -> us.fatehi:schemacrawler-archetype-plugin-command (-)
1607: remote -> us.fatehi:schemacrawler-archetype-plugin-dbconnector (-)
1608: remote -> us.fatehi:schemacrawler-archetype-plugin-lint (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 792:
第一次用mvn会下载很多jar文件,比较慢,可以看到中央仓库有1608个插件,默认提供792编号的插件,enter选择默认;


1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:


版本中默认选择6 quickstart,回车
groupId项目所属组标识
artifactId项目名称
version项目的版本,用默认,回车
package项目名称,默认和artifactId一样的,回车
输入Y确认以上配置
Define value for property 'groupId': : com.jikexueyuan
Define value for property 'artifactId': : mvnstudy
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.jikexueyuan: :
Confirm properties configuration:
groupId: com.jikexueyuan
artifactId: maven
version: 1.0-SNAPSHOT
package: com.jikexueyuan
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /root
[INFO] Parameter: package, Value: com.jikexueyuan
[INFO] Parameter: groupId, Value: com.jikexueyuan
[INFO] Parameter: artifactId, Value: maven
[INFO] Parameter: packageName, Value: com.jikexueyuan
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /root/maven
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:51 min
[INFO] Finished at: 2016-06-10T13:55:08+08:00
[INFO] Final Memory: 14M/52M
[INFO] ------------------------------------------------------------------------
root@spark:~# ls
cleanjob   hadoop.sh  input         sbt-0.13.11.deb  WordCount
css.sh     hello      metastore_db  target
derby.log  image.jpg  mvnstudy      testtable.java


root@spark:~/mvnstudy/src/main/java/com/jikexueyuan# ls
App.java
打包
root@spark:~/mvnstudy# mvn package
结果:
utils/3.0/plexus-utils-3.0.jar (221 KB at 130.3 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.1/plexus-archiver-2.1.jar (181 KB at 90.5 KB/sec)
[INFO] Building jar: /root/mvnstudy/target/mvnstudy-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:30 min
[INFO] Finished at: 2016-06-10T14:04:01+08:00
[INFO] Final Memory: 17M/41M
[INFO] ------------------------------------------------------------------------
查看jar文件


root@spark:~/mvnstudy# ls
pom.xml  src  target
root@spark:~/mvnstudy# ls target/
classes         maven-status               surefire-reports
maven-archiver  mvnstudy-1.0-SNAPSHOT.jar  test-classes
root@spark:~/mvnstudy#
运行
root@spark:~/mvnstudy# java -cp target/mvnstudy-1.0-SNAPSHOT.jar com.jikexueyuan.App
Hello World!
成功。
参考:
eclipse maven:http://www.jikexueyuan.com/course/580_1.html


放自己的java代码:比如MvnTest.java
内容如下:
package com.test;


/**
 * Hello world!
 *
 */
import java.util.Date;


public class MvnTest {
        public static void main(String[] args) throws Exception {
                Date d=new Date();
                Class cl=d.getClass();
                String name=cl.getName();
                System.out.println(name);
                String className="java.util.Date";
                Class cl2=Class.forName(className);
                System.out.println(cl2);
                Class cl11=Date.class;
                System.out.println(cl11);
                Class cl12=int.class;
                Class cl13=Double[].class;
                System.out.println(cl12);
                System.out.println(cl13);
        }
}
       
root@spark:~/mvntest/src/main/java/com/test# ls
App.java  MvnTest.java
打包
cd ~/mvntest
mvn package
root@spark:~/mvntest/target# ls
classes         maven-status              surefire-reports
maven-archiver  mvntest-1.0-SNAPSHOT.jar  test-classes
运行
root@spark:~/mvntest# java -cp target/mvntest-1.0-SNAPSHOT.jar com.test.MvnTest
结果:
java.util.Date
class java.util.Date
class java.util.Date
int
class [Ljava.lang.Double;
成功
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值