安装了lnmp怎么做网站,厦门seo搜索排名,企业起名大全参考,网站建设对企业发展的意义在进行java开发时经常遇到一种情况#xff0c;就是windows下和linux下需要引入的jar包是不一样的。
比如说我们需要使用java来操作OpenGL库#xff0c;我们就需要通过maven引入JOGL的依赖#xff0c;
然而在window下和在linux下需要引入JOGL的依赖是不一样的#xff1a; …在进行java开发时经常遇到一种情况就是windows下和linux下需要引入的jar包是不一样的。
比如说我们需要使用java来操作OpenGL库我们就需要通过maven引入JOGL的依赖
然而在window下和在linux下需要引入JOGL的依赖是不一样的
在window下需要引入JOGL的-win版本的依赖。在linux下则需要引入JOGL的-linux版本的依赖。
那么我们应该怎么做呢如何灵活配置和指定不同环境的依赖呢我们需要使用Maven配置文件中的 profiles 元素。
下面是一个常用的pom.xml
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.xxx.xxx/groupIdartifactIdxxx-xxx/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdxxx-xxx/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency.../dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdversion${spring-boot.version}/versionconfigurationfinalName${project.artifactId}/finalNamelayersenabledtrue/enabled/layersincludeSystemScopetrue/includeSystemScope/configurationexecutionsexecutiongoalsgoalrepackage/goal/goals/execution/executions/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-surefire-plugin/artifactIdversion2.20.1/versionconfigurationskipTeststrue/skipTests/configuration/plugin/plugins/build
/project现在我需要操作OpenGL在开发时是win环境amd64需要加入如下依赖: dependencygroupIdorg.jogamp.jogl/groupIdartifactIdjogl-all/artifactIdversion2.3.2/versionclassifiernatives-linux-amd64/classifier/dependencydependencygroupIdorg.jogamp.gluegen/groupIdartifactIdgluegen-rt/artifactIdversion2.3.2/versionclassifiernatives-linux-amd64/classifier/dependency但是上生产的时候是运行在Linux上的则需要将上述依赖改为Linux的如下: dependencygroupIdorg.jogamp.jogl/groupIdartifactIdjogl-all/artifactIdversion2.3.2/versionclassifiernatives-windows-amd64/classifier/dependencydependencygroupIdorg.jogamp.gluegen/groupIdartifactIdgluegen-rt/artifactIdversion2.3.2/versionclassifiernatives-windows-amd64/classifier/dependency那么如何通过maven的配置来指定使用哪个依赖呢则需要使用 Maven 的Profiles在pom中添加如下配置 dependencies.../dependenciesprofilesprofileidwin/idpropertiesprofileActivewin/profileActivedb.urljdbc:mysql://localhost/win_db/db.url/propertiesactivationactiveByDefaulttrue/activeByDefault!-- 根据属性值激活 --propertynameenv/namevaluetest/value/property/activationdependenciesdependencygroupIdorg.jogamp.jogl/groupIdartifactIdjogl-all/artifactIdversion2.3.2/versionclassifiernatives-windows-amd64/classifier/dependencydependencygroupIdorg.jogamp.gluegen/groupIdartifactIdgluegen-rt/artifactIdversion2.3.2/versionclassifiernatives-windows-amd64/classifier/dependency/dependencies/profileprofileidlinux/idpropertiesprofileActivelinux/profileActivedb.urljdbc:mysql://localhost/linux_db/db.url/propertiesactivationactiveByDefaultfalse/activeByDefault!-- 根据属性值激活 --propertynameenv/namevalueprd/value/property/activationdependenciesdependencygroupIdorg.jogamp.jogl/groupIdartifactIdjogl-all/artifactIdversion2.3.2/versionclassifiernatives-linux-amd64/classifier/dependencydependencygroupIdorg.jogamp.gluegen/groupIdartifactIdgluegen-rt/artifactIdversion2.3.2/versionclassifiernatives-linux-amd64/classifier/dependency/dependencies/profile/profilesid 元素用于给 Profile 分配一个唯一的标识符使用maven构建时根据此id选择需要激活的环境。properties元素自定义的属性不同的 Profile 被激活时里面的配置将被设置为不同的值在其他地方可以获取到并使用改属性比如在资源文件中使用 ${} 格式的占位符引用属性的值profileActive${profileActive}
db.url${db.url}activation 元素 定义了 Profile 的激活条件。 activeByDefault元素表示是否默认激活设置为 true表示在没有明确指定其他 Profile 时该配置将自动激活可以使用命令mvn clean package -Pwin或mvn clean package -Plinux来指定对应的profile id。property元素根据属性 env 的值来激活可以使用命令-Denvtest或-Denvprd来激活。 dependencies元素该环境下对应的依赖。build元素该环境下的构建选项。......其他元素用处不多不展开介绍。
正如上面所说这时候在构建时就可以指定选项来打包不同的依赖了 通过profile id打包 mvn clean package -Pwin通过自定义环境变量打包 mvn clean package -Denvtest