网站优化设计方案怎么做,期货网站开发,推荐购物网站建设,网站的基本功能在使用 maven 编译项目时#xff0c;我们有时候会需要引入本地的 jar 包作为依赖#xff08;不部署到本地仓库#xff09;#xff0c;一般会使用 scope 为 system 的标签来引入#xff0c;如下所示#xff1a;
dependencygroupIdcom.example/groupI…在使用 maven 编译项目时我们有时候会需要引入本地的 jar 包作为依赖不部署到本地仓库一般会使用 scope 为 system 的标签来引入如下所示
dependencygroupIdcom.example/groupIdartifactIdsystem-dependency/artifactIdversion1.0.0/versionscopesystem/scopesystemPath${basedir}/lib/system-dependency.jar/systemPath
/dependency此时pom 中往往还有其他的依赖是从远端的 maven 仓库下载。如果我们需要同时将本地 jar 和远端下载的 jar 同时注册到 classpath 中我们可以这么配置插件。
一、配置maven-dependency-plugin
首先利用maven-dependency-plugin插件将 runtime 和 system 的依赖都拷贝到指定路径这里是选择的路径是target/lib plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-dependency-plugin/artifactIdversion3.4.0/versionexecutionsexecutionidcopy-runtime-dependency/idphasepackage/phasegoalsgoalcopy-dependencies/goal/goalsconfigurationexcludeTransitivefalse/excludeTransitiveoutputDirectory${project.build.directory}/lib/outputDirectoryincludeScoperuntime/includeScope/configuration/executionexecutionidcopy-system-dependency/idphasepackage/phasegoalsgoalcopy-dependencies/goal/goalsconfigurationexcludeTransitivefalse/excludeTransitiveoutputDirectory${project.build.directory}/lib/outputDirectoryincludeScopesystem/includeScope/configuration/execution/executions/plugin二、配置maven-jar-plugin
然后利用maven-jar-plugin插件将这些所有依赖的 jar 都注册到 classpath中如下所示 plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-jar-plugin/artifactIdversion3.3.0/versionconfigurationarchivemanifestaddClasspathtrue/addClasspathclasspathPrefixlib//classpathPrefixmainClasscom.xx.YourMain/mainClass/manifestmanifestEntriesClass-Pathlib/system-dependency.jar/Class-Path/manifestEntries/archive/configuration/plugin这里的lib/system-dependency.jar对应的就是我们通过maven-dependency-plugin插件拷贝之后的新 jar而不是最初的 systemPath 路径。
三、编译 执行
最终通过mvn clean package命令编译之后就可以在我们自己的 jar的MANIFEST.MF文件中查看所有的 jar 都被写到classpath包括本地 jar。然后我们就可以通过 java -jar xxx.jar直接执行我们自己的程序。