夜光序言:
我会努力奋斗 不停地想要成功 都是因为我想成为那个配得上你的人。
正文:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.guicedemo</groupId>
<artifactId>guicedemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>guicedemo Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>guicedemo</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
第一步:修改pom.xml,添加依赖jar包
第二步:
package com.genius.test;
/*
*
* @title MyApplet
* @describe 提供run方法
* @author
* @version
* @date 2019/6/18
*
*/
public interface MyApplet extends Runnable{
//how to write~
}
第三步:
package com.genius.test;
/*
*
* @title HellowWorldPrinter
* @describe 提供打印hi功能~~
* @author hy
* @version
* @date 2019/6/18
*
*/
public class HellowWorldPrinter implements MyApplet {
private void printHellowWorld(){
System.out.println("hi~~");
}
@Override
public void run(){
printHellowWorld();
}
}
第四步:
package com.genius.test;
/*
*
* @title Configuration
* @describe 程序启动配置类
* @author hy
* @version
* @date 2019/6/18
*
*/
public class Configuration {
public static MyApplet getMainApplet(){
return new HellowWorldPrinter();
}
}
最后一步:
package com.genius.test;
/*
*
* @title App
* @describe 启动类,改造HelloWorld类
* @author hy
* @version
* @date 2019/6/18
*
*/
public class App {
/**
* main方法的作用
* bootstrap:
* parse command line:解析命令行参数
* set up environment:配置环境参数
* kick off main logic:启动程序逻辑
*
*/
public static void main(String[] args) {
MyApplet mainApplet = Configuration.getMainApplet();
mainApplet.run();
}
}