Java部署_IntelliJ创建一个可运行的jar包(实践)

一、本文目的:使用Intellij Idea 13生成一个简单可执行的jar,用于快速在linux验证某个功能

二、项目源码
1、结构图
 2、StaticC1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.gossip;
 
public class StaticC1 {
 
    private String userName;
 
    private String age;
 
    private String birthDate;
 
    public String getUserName() {
        return userName;
    }
 
    public void setUserName(String userName) {
        this.userName = userName;
    }
 
    public String getAge() {
        return age;
    }
 
    public void setAge(String age) {
        this.age = age;
    }
 
    public String getBirthDate() {
        return birthDate;
    }
 
    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }
 
    @Override
    public String toString() {
        return "StaticC1{" +
                "userName='" + userName + '\'' +
                ", age='" + age + '\'' +
                ", birthDate='" + birthDate + '\'' +
                '}';
    }
}

3、Provider.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.gossip;
 
import java.util.Date;
 
 
public class Provider {
 
    private static StaticC1 s1;
 
    public static void main(String[] args) {
        System.out.println("当前线程:" + Thread.currentThread().getName());
        System.out.println("当前时间:" + new Date());
        System.out.println("主线程休眠5分钟");
        s1 = new StaticC1();
 
        System.out.println("StaticC1:" + s1.toString());
        try {
            //休眠5分钟
            Thread.sleep(300000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


三、打包过程

1、File-->Project Structure

这里选择Empty






2、Build打包

jar包生成目录:simplecode\out\artifacts\simplecode\simplecode.jar




四、Linux运行jar包

 java -jar simplecode.jar






posted @ 2016-11-23 15:03    阅读(909)  评论(0编辑  收藏  举报