How to build jar package with IntelliJ IDEA
1. Jar package without maven
1. After writing the Java project, click File --> Project Structure, and then follow the steps shown below to perform the packaging operation.
If there are some additional files in the project, you can add the files to the jar package in the following ways.
//如果我们将项目打成jar包之后,a.log文件不识别,此时我们需要使用类加载器读取jar包中的文件 要求文件必须在一个resources格式的目录下
//这行代码只能在jar包中使用,如果项目没有打jar包这行代码无法识别a.log文件
InputStream inputStream = DataGenerator.class.getClassLoader().getResourceAsStream("a.log");
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
At this point, the project packaging is completed, and then go to the console server to enter the commandjava -jar data-generator.jar
You can run the jar package.
2. Maven creates jar package
Click Maven on the far right side of the interface, then click Lifecycle, click package until the console outputs BUILD SUCCESS, and the package is successful!