Background:
Project requirements, simply post maven-dependent addresses on the page to download dependencies directly
For example
<dependency> <groupId>com.avides.springboot.testcontainer</groupId> <artifactid >springboot-testcontainer-common</artifactId> <version>0.1.0-rc6</version></ Dependency>
Put this on, the project will be able to download maven dependencies directly
Practice:
Need to use the MAVEN command on Linux (This command is also available on Windows, depending on the practice)
Note: You need to install MAVEN first, and configure the environment variables, it is possible that the warehouse address in the configuration is consistent with the command
MVN dependency:get-dremoterepositories=http://repo1.maven.org/maven2/-dgroupid=junit-dartifactid= junit-dversion=4.8.2
Java Specific wording
Public Process exec (string[] cmdarray); // Linux under Runtime.getruntime (). EXEC (new string[]{"/bin/sh", "-C", "Cmds"}). WaitFor (); // windows under Runtime.getruntime (). EXEC (new string[]{"cmd", "/C", Cmds}). WaitFor ();
Several methods of process
1, Destroy (): Kill the child process
2, Exitvalue (): Returns the exit value of the child process, the value 0 indicates normal termination
3, Geterrorstream (): Gets the error stream of the child process
4, getInputStream (): Gets the input stream of the child process
5, Getoutputstream (): Gets the output stream of the child process
6.WaitFor (): Causes the current thread to wait and, if necessary, waits until the process represented by that process object has been terminated. If the child process has been terminated, this method returns immediately. If the child process is not terminated, the calling thread will be blocked, knowing that the exit child process, according to management, 0 indicates normal termination.
Note: In Java, calling runtime threads to execute scripts is very resource-intensive, so remember not to use them frequently!
When calling runtime to execute a script, the JVM actually opens a sub-thread to invoke the JVM's system command, which opens three channels: the input stream, the output stream, the error stream, where the output stream is the channel that the child thread is going to call.
As we all know, waitfor is waiting for the child thread to execute the command after the end of the access, but in runtime, open the program's command if not closed, no operator thread end, such as the following code.
Attention:
In practice, if the Linux command fails on a Linux server, such as the not found command, it is executed, and the code will continue to go down. So make sure the command is correct, or use the return value to judge! The return and not called return values of the call WAITFOR () are different types.
Such a download method can only rely on the download to the local MAVEN configuration of the warehouse, if there are other requirements, such as the need for my project is to scan the other path under the facade package exists, then after I download the dependency, there is another operation is to copy the same jar package to the other path. In the process of replication need to pay attention to the MAVEN directory structure, to ensure that every time the stitching is correct.
In addition, there is a small problem in the operation process, the use of SECURECRT login to the Linux server, you must first execute the source. BASHRC command, and then start the project in this window, so that you can properly execute the Java code output of the Linux command, must be the same window! Please consult.
Calling Linux or MAVEN commands on a linux server using Java code