0 课程地址
https://coding.imooc.com/lesson/201.html#mid=12746
1 重点关注
1.1 本节内容
使用dubbo内置main打包jar启动
1.2 主要改动点
涉及父项目,common项目,service和api项目共4个,
涉及
a service的 pom文件引入build
b service的 pom文件修改打包方式为jar包
c 上述操作完成后 右键service子项目,maven ->update project ->选中service子项目,点击ok,进行pom文件依赖的jar包更新
d 右键父项目,run as maven install,注意:这个方法生成了api jar包,解决了昨天一直生成不了apijar包的问题
e 进入service子项目生成的target路径下,cmd 运行 java -jar imooc-dubbo-item-service.jar
f 等待运行完成即可
- a service的 pom文件引入build
pom.xml引用以下build
--<targetPath>${project.build.directory}/classes</targetPath> 可以将资源文件打进包里
--<targetPath>${project.build.directory}/classes/META-INF/spring</targetPath> spring-context.xml已经聚合了所有的spring相关的配置文件(可以参考上节,也可以看下spring-context.xml)
--<artifactId>lifecycle-mapping</artifactId> 可以排除运行时的一些小问题,注意,首次加载要下载
--<artifactId>maven-jar-plugin</artifactId> 打包的方式,打完包,依赖都会有
--<mainClass>com.alibaba.dubbo.container.Main</mainClass> dubbo内置容器的container进行打包
<build>
<finalName>imooc-dubbo-item-service</finalName>
<resources>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
<directory>src/main/resources/spring</directory>
<filtering>true</filtering>
<includes>
<include>spring-context.xml</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<manifest>
<mainClass>com.alibaba.dubbo.container.Main</mainClass>
<useUniqueVersions>false</useUniqueVersions>
<addClasspath>true</