Using IntelliJ IDEA build Maven java project

------------ ------------ restore content begins

Java developers, choose IntelliJ IDEA software.
With respect to the installation configuration software can refer https://www.jianshu.com/p/935367fd0ad4 (content 1-4).
This article is groping in the learning process, continue to solve the problem and then go back again just to write a complete process flow, the following screenshot you can see a different project name, but the code relies used are the same, to ensure the process is accurate.

1. Create a new project

 
 
 
 

 

maven path is configured to install, this does not need to modify the page
 
 

 

The default path and project name, project name that is to fill out ArtifactID
 
 
Click Finish, the project created.

2. Download and test the dependence

 

 

After the project is created, the lower right corner will be prompted to download the software dependencies, Enable Auto-Import download.
 
 

 

The new project default output "Hello World!", Start the test
 
 
The console displays a Hello World, the project created.
 
 

3. coding

The main functions are as follows: xml file read and write, Oracle database to read and write, the output log.

 

Given the overall program structure.
 
 

1.XML file read and write

There are many use dom4j, xml read and write code online.

 

New Java Class files (XmlRW), the code is written, the introduction of dependency. The method of unidentified SAXReader, can be selected after pressing ALT + ENTER key, add dependency maven
 
 
 
 
Press ALT + ENTER key to select the Import class again.

Write the code according to their needs, all depend on the completion and references, eliminate all errors.

2. Profiles

Project configuration file is a separate file, which can be written to the database connection configuration information, route information. These independent content, you can easily change the configuration, such as database connection address has changed, you only need to change the configuration file.
Here we experienced many twists and turns, on the establishment of the location of this file, referenced in the code, and the introduction of the file playing jar package and the call document, recording the following runtime jar of my success.

 

New Resource Bundle file (res / config.properties), here emphasize the folder where the file config.properties res should Resources Folders, right-setting method for the selected file folder
 
 
 
 
If you do not do this, the following reference code can not find the configuration file, and finally playing jar package configuration file will not be in the package.
config.properties inside written to the database connection information and log4j (write log file) configuration information, does not describe specific configuration.
inPath=C:\\Users\\conan\\Desktop\\ outPath=D:\\ url=jdbc:oracle:thin:@127.0.0.1:1521:orcl username=interface password=123456 driverClass=oracle.jdbc.OracleDriver ### 输出到日志文件 ### log4j.rootLogger = DEBUG,File log4j.appender.File=org.apache.log4j.DailyRollingFileAppender log4j.appender.File.File=D:\\app.log log4j.appender.File.DatePattern=_yyyyMMdd log4j.appender.File.Threshold=ALL log4j.appender.File.layout=org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss}]%m%n 

In the method of reading configuration information file ConfigManager

Properties prop = new Properties(); System.setProperty("log4j.configuration", "config.properties"); ///log4j配置读取 logger = Logger.getLogger(ConfigManager.class ); logger.info("Success"); ///输出log,此处作为log4j的使用示例 InputStream in = ConfigManager.class.getClassLoader().getResourceAsStream("config.properties"); prop.load(in); ///加载其他属性列表 inPath = prop.getProperty("inPath"); outPath = prop.getProperty("outPath"); url = prop.getProperty("url"); username = prop.getProperty("username"); password = prop.getProperty("password"); driverClass = prop.getProperty("driverClass"); in.close(); 

3.Oracle database to read and write

Use ojdbc6, when maven references, there have been references to the problem of failure, you can refer https://www.jianshu.com/p/c0b47f202a5a .
Oracle to read and write code there are many online, find examples of writing code they need.

4. Test

After the function of each part in series according to their needs, startup testing locally generated target directory.
After adjusting pass can officially hit the jar package.

4. jar packaging

1. Configuration

 
 
 
 

 

MANIFEST.MF useless default path, to change into the root directory, see FIG overall project structure given above
 
 

 

Click Apply-> OK
 
 

2. Package

 
 
 
 

 

After the completion of Build, generate out directory
 
 

 

Find the jar package, use WinRAR to open the View (be careful not to unzip), which contains config.properties file, drag it out, modified linux system configuration, mainly ip route and Oracle connections, the modified file directly dragged into to open in WinRAR (again reminded not to decompress recompression),
 
 
Then you can put into a jar package linux system to be tested.

3.Linux deployment

The main two aspects.
1. JDK installed Java ( https://www.jianshu.com/p/56e0e98421ec ), so that it can run the jar package,
2. the system can confirm linux connection destination database system, a problem can refer to https: // www .jianshu.com / p / 1767ce2a7a43 be resolved.

4. Run the test

java -jar IOTask.jar, check for an error, function is realized.

5. Find and shutdown process

[root@localhost ~]# ps aux|grep IOTask.jar root 13952 0.4 5.7 2250820 58024 pts/0 Sl+ 12:16 0:02 java -jar IOTask.jar root 16852 0.0 0.0 112644 960 pts/1 R+ 12:24 0:00 grep --color=auto IOTask.jar 

Where the second row as the first PID is currently running, shut down the process

[root@localhost ~]# kill -9 13952 

Query again, the following results appear to indicate successful close

[root@localhost ~]# ps aux|grep IOTask.jar root 17920 0.0 0.0 112644 964 pts/1 R+ 12:28 0:00 grep --color=auto IOTask.jar


Author: Shan-Shan Li _8ef1
link: https: //www.jianshu.com/p/4f8615898ad3
Source: Jane books
are copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

End ------------ ------------ restore content

Guess you like

Origin www.cnblogs.com/rpc1024/p/12329751.html