Maven打包成可直接运行jar

Main.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
package cn.huangdayu.falsework.provider.main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	
	private static Logger logger = LoggerFactory.getLogger(Main.class);
    
    public static void main(String[] args) {
        try {
        	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
            context.start();
            System.in.read();
        } catch (Exception e) {
        	logger.error(" Dubbo provider context start error:",e.getMessage());
        }
        synchronized (Main.class) {
            while (true) {
                try {
                	Main.class.wait();
                } catch (InterruptedException e) {
                	logger.error("synchronized error:",e.getMessage());
                }
            }
        }
    }
}

pom.xml

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
<build> 
  <finalName>falsework-provider</finalName>  
  <plugins> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId>  
      <artifactId>maven-shade-plugin</artifactId>  
      <version>1.7</version>  
      <executions> 
        <execution> 
          <phase>package</phase>  
          <goals> 
            <goal>shade</goal> 
          </goals>  
          <configuration> 
            <finalName>falsework-provider-app</finalName>  
            <shadedArtifactAttached>true</shadedArtifactAttached>  
            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>  
            <transformers> 
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
                <mainClass>cn.huangdayu.falsework.provider.main.Main</mainClass> 
              </transformer>  
              <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
                <resource>META-INF/spring.handlers</resource> 
              </transformer>  
              <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
                <resource>META-INF/spring.schemas</resource> 
              </transformer>  
              <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
                <resource>META-INF/spring.tooling</resource> 
              </transformer> 
            </transformers> 
          </configuration> 
        </execution> 
      </executions> 
    </plugin> 
  </plugins> 
</build>

后台运行

1
nohup java -Ddubbo.service.server.port=20880 -jar falsework-provider-app.jar > 2018-10-27-falsework-provider-app.log &

今日诗词

作者信息