-
新建一个module,如果不会新建的话,参考:Intellij Idea新建module。命名为jar_test。
-
新建一个java类DateUtil,可以输出当前时间对应的是星期几。代码如下:
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
public static String getTodayWeek() {
String[] weekList = {"星期日", "星期一", "星期二", "星期三", "星期四", " 星期五", "星期六"};
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(System.currentTimeMillis()));
int week_index = calendar.get(Calendar.DAY_OF_WEEK) - 1;
if (week_index < 0) {
week_index = 0;
}
return weekList[week_index];
}
}
将这个jar_test的Module打包成jar。
-
File -->Project Structure -->Artifacts --> Jar --> From module with dependencies.
-
Build --> Build Artifacts
-
等会儿,就能看到输出的jar文件
-
新建项目,导入jar包,这个步骤可以参考:https://blog.csdn.net/qq_26525215/article/details/53239123。查看里面的MANIFEST.MF文件: