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

本文介绍如何使用IntelliJ IDEA 13将Java项目打包成可在Linux上运行的简单可执行jar文件。通过具体步骤和示例代码,展示了项目的结构、核心类的实现及如何设置和构建项目。
一、本文目的:使用Intellij Idea 13生成一个简单可执行的jar,用于快速在linux验证某个功能

二、项目源码
1、结构图
35158-20161123150323581-825542927.png
 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

35158-20161123150324331-1034073765.png

35158-20161123150324565-258753682.png

35158-20161123150324987-520665634.png

35158-20161123150325440-701275769.png

35158-20161123150325925-1156462386.png

2、Build打包

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

35158-20161123150326503-1096344090.png



四、Linux运行jar包

 java -jar simplecode.jar

35158-20161123150326862-272375628.png





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值