由于某种原因,我必须使用环境变量而不是将系统属性传递给mvn命令。因此,我使用${env.PROFILE}作为属性名称,在pom.xml中的配置如下:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>${env.PROFILE}</name>
<value>dev</value>
</property>
</activation>
<properties>
<profile.assembly.suffix></profile.assembly.suffix>
</properties>
</profile>
<profile>
<id>online</id>
<activation>
<property>
<name>${env.PROFILE}</name>
<value>online</value>
</property>
</activation>
<properties>
<profile.assembly.suffix>-online</profile.assembly.suffix>
</properties>
</profile>
</profiles>
然后,我尝试将配置文件激活到在线状态,但是失败了,命令行显示如下:
E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\LobbyServer>set PROFILE=online
E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\LobbyServer>echo %PROFILE%
online
E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\LobbyServer>mvn help:active-profiles
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for Fusion:LobbyServer:jar:1.0
[WARNING] 'dependencies.dependency.systemPath' for Fusion:Fusion-Core:jar should not point at files within the project directory, ${project.basedir}/../libs/Fusion-Core-2.0.jar will be unresolvable by dependent projects @ line 98, column 25
[WARNING] 'dependencies.dependency.systemPath' for Fusion:common-plugin:jar should not point at files within the project directory, ${project.basedir}/../libs/common-plugin-1.0.jar will be unresolvable by dependent projects @ line 106, column 25
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: redis.clients:jedis:jar -> duplicate declaration of version (?) @ line 227, column 21
[WARNING] 'dependencyManagement.dependencies.dependency.systemPath' for Fusion:Fusion-Core:jar should not point at files within the project directory, ${project.basedir}/libs/Fusion-Core-2.0.jar will be unresolvable by dependent projects @ Fusion:Fusion-Server:1.0, E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\pom.xml, line 64, column 25
[WARNING] 'dependencyManagement.dependencies.dependency.systemPath' for Fusion:common-plugin:jar should not point at files within the project directory, ${project.basedir}/libs/common-plugin-${project.version}.jar will be unresolvable by dependent projects @ Fusion:Fusion-Server:1.0, E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\pom.xml, line 72, column 25
[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-core:jar -> duplicate declaration of version ${spring.version} @ Fusion:Fusion-Server:1.0, E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\pom.xml, line 167, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 67, column 21
[WARNING] 'dependencyManagement.dependencies.dependency.systemPath' for Fusion:Fusion-Core:jar refers to a non-existing file E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\LobbyServer\libs\Fusion-Core-2.0.jar @ Fusion:Fusion-Server:1.0, E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\pom.xml, line 64, column 25
[WARNING] 'dependencyManagement.dependencies.dependency.systemPath' for Fusion:common-plugin:jar refers to a non-existing file E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\LobbyServer\libs\common-plugin-1.0.jar @ Fusion:Fusion-Server:1.0, E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\pom.xml, line 72, column 25
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------------< Fusion:LobbyServer >-------------------------
[INFO] Building LobbyServer 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:active-profiles (default-cli) @ LobbyServer ---
[INFO]
Active Profiles for Project 'Fusion:LobbyServer:jar:1.0':
The following profiles are active:
- dev (source: Fusion:LobbyServer:1.0)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.661 s
[INFO] Finished at: 2019-11-06T12:48:49+08:00
[INFO] ------------------------------------------------------------------------
然后我打开了Maven的调试模式(-X),属性看起来像这样:
[DEBUG] properties used {spring-data-common.version=1.12.6.RELEASE, file.encoding.pkg=sun.io, env.PROMPT=$P$G, okhttp3.version=3.8.1, java.home=D:\Software\Java\jdk1.8.0_121\jre, env.CLION=D:\Software\CLion 2019.1.4\bin;, classworlds.conf=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\..\bin\m2.conf, profile.assembly.suffix=, java.endorsed.dirs=D:\Software\Java\jdk1.8.0_121\jre\lib\endorsed, env.USERNAME=zhengtongshan, env.PHPSTORM=D:\Software\JetBrains\PhpStorm 2019.2.2\bin;, servlet.version=3.1.0, sun.os.patch.level=, java.vendor.url=http://java.oracle.com/, env.COMPUTERNAME=DESKTOP-R7DT0R0, env.=C:=C:\Users\zhengtongshan, java.version=1.8.0_121, commons-beanutils.version=1.9.3, env.DRIVERDATA=C:\Windows\System32\Drivers\DriverData, fastjson.version=1.2.62, spring-data-redis.version=1.8.4.RELEASE, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, env.USERPROFILE=C:\Users\zhengtongshan, apache.httpclient.version=4.5.3, jedis.version=2.9.0, user.name=zhengtongshan, sun.io.unicode.encoding=UnicodeLittle, sun.jnu.encoding=GBK, java.runtime.name=Java(TM) SE Runtime Environment, env.LOCALAPPDATA=C:\Users\zhengtongshan\AppData\Local, env.COMMONPROGRAMW6432=C:\Program Files\Common Files, java.specification.name=Java Platform API Specification, user.timezone=Asia/Shanghai, user.script=, path.separator=;, env.MAVEN_CMD_LINE_ARGS=-e -X -f E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\../RoomServer/pom.xml clean assembly:assembly, env.PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel, file.encoding=GBK, sun.java.command=org.codehaus.plexus.classworlds.launcher.Launcher -e -X -f E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\../RoomServer/pom.xml clean assembly:assembly, env.NUMBER_OF_PROCESSORS=12, env.APPDATA=C:\Users\zhengtongshan\AppData\Roaming, env.WINDIR=C:\Windows, java.io.tmpdir=C:\Users\ZHENGT~1\AppData\Local\Temp\, user.language=zh, line.separator=
, env.COMMONPROGRAMFILES=C:\Program Files\Common Files, java.vm.info=mixed mode, sun.desktop=windows, java.vm.specification.name=Java Virtual Machine Specification, project.reporting.outputEncoding=UTF-8, env.PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, env.WDIR=E:\, env.ONEDRIVE=C:\Users\zhengtongshan\OneDrive, env.USERDOMAIN_ROAMINGPROFILE=DESKTOP-R7DT0R0, commons-io.version=2.5, trove4j.version=3.0.3, env.LOGONSERVER=\\DESKTOP-R7DT0R0, env.PSMODULEPATH=C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules, java.awt.printerjob=sun.awt.windows.WPrinterJob, commons-codec.version=1.9, env.JAVACMD=D:\Software\Java\jdk1.8.0_121\bin\java.exe, env.JVMCONFIG=\.mvn\jvm.config, env.PUBLIC=C:\Users\Public, env.USERDOMAIN=DESKTOP-R7DT0R0, env.PROCESSOR_LEVEL=6, env.PROGRAMFILES(X86)=C:\Program Files (x86), env.=EXITCODE=00000000, env.FILE_ARG=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\../RoomServer/pom.xml, os.name=Windows 10, java.specification.vendor=Oracle Corporation, env.TMP=C:\Users\ZHENGT~1\AppData\Local\Temp, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, env.OS=Windows_NT, java.library.path=D:\Software\Java\jdk1.8.0_121\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\Software\Java\jdk1.8.0_121\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Software\TortoiseSVN\bin;D:\Software\Git\cmd;E:\FusionDB\mongodb-3.2.17\bin;E:\FusionDB\Redis-x64-3.2.100;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\Software\Cygwin\bin;D:\Software\Calibre2\;D:\Software\apache-ant-1.8.2\bin\;D:\Software\apache-maven-3.6.2-bin\apache-maven-3.6.2\bin;D:\Software\Python3.6\Scripts\;D:\Software\Python3.6\;C:\Users\zhengtongshan\AppData\Local\Microsoft\WindowsApps;;D:\Software\JetBrains\IntelliJ IDEA 193.4386.10\bin;;D:\Software\JetBrains\JetBrains Rider 2019.1.2\bin;;D:\Software\CLion 2019.1.4\bin;;D:\Software\JetBrains\PhpStorm 2019.2.2\bin;;., env.PROGRAMW6432=C:\Program Files, env.PATH=D:\Software\Java\jdk1.8.0_121\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Software\TortoiseSVN\bin;D:\Software\Git\cmd;E:\FusionDB\mongodb-3.2.17\bin;E:\FusionDB\Redis-x64-3.2.100;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\Software\Cygwin\bin;D:\Software\Calibre2\;D:\Software\apache-ant-1.8.2\bin\;D:\Software\apache-maven-3.6.2-bin\apache-maven-3.6.2\bin;D:\Software\Python3.6\Scripts\;D:\Software\Python3.6\;C:\Users\zhengtongshan\AppData\Local\Microsoft\WindowsApps;;D:\Software\JetBrains\IntelliJ IDEA 193.4386.10\bin;;D:\Software\JetBrains\JetBrains Rider 2019.1.2\bin;;D:\Software\CLion 2019.1.4\bin;;D:\Software\JetBrains\PhpStorm 2019.2.2\bin;, library.jansi.path=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\..\lib\jansi-native\windows64, java.class.version=52.0, maven.multiModuleProjectDirectory=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool, javaxValidation.version=1.1.0.Final, env.HOMEDRIVE=C:, env.SYSTEMROOT=C:\Windows, spring.version=4.3.9.RELEASE, env.COMSPEC=C:\Windows\system32\cmd.exe, sun.boot.library.path=D:\Software\Java\jdk1.8.0_121\jre\bin, project.build.sourceEncoding=UTF-8, env.SYSTEMDRIVE=C:, env.PROCESSOR_REVISION=9e0a, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, user.variant=, mongo-java-driver.version=3.3.0, netty.version=4.1.6.Final, junit.version=RELEASE, env.PROGRAMFILES=C:\Program Files, java.vm.specification.version=1.8, env.POM_DIR=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\RoomServer, env.PROGRAMDATA=C:\ProgramData, slf4j.version=1.7.25, awt.toolkit=sun.awt.windows.WToolkit, env.MAVEN_HOME=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\.., sun.cpu.isalist=amd64, sun.stderr.encoding=ms936, env.MAVEN_PROJECTBASEDIR=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool, java.ext.dirs=D:\Software\Java\jdk1.8.0_121\jre\lib\ext;C:\Windows\Sun\Java\lib\ext, os.version=10.0, env.ERROR_CODE=0, user.home=C:\Users\zhengtongshan, env.PROFILE=online, java.vm.vendor=Oracle Corporation, env.JETBRAINS RIDER=D:\Software\JetBrains\JetBrains Rider 2019.1.2\bin;, env.JAVA_HOME=D:\Software\Java\jdk1.8.0_121, user.dir=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool, maven.conf=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\../conf, env.COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files, log4j.version=2.8.2, sun.cpu.endian=little, spring-data-mongo.version=1.10.4.RELEASE, env.ALLUSERSPROFILE=C:\ProgramData, env.CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher, env.PROCESSOR_ARCHITECTURE=AMD64, java.vm.version=25.121-b13, java.class.path=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\..\boot\plexus-classworlds-2.5.2.jar, env.=::=::\, org.slf4j.simpleLogger.defaultLogLevel=debug, env.HOMEPATH=\Users\zhengtongshan, env.EXEC_DIR=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool, os.arch=amd64, maven.build.version=Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00), env.SESSIONNAME=Console, guava.version=19.0, sun.java.launcher=SUN_STANDARD, java.vm.specification.vendor=Oracle Corporation, file.separator=\, gson.version=2.7, java.runtime.version=1.8.0_121-b13, sun.boot.class.path=D:\Software\Java\jdk1.8.0_121\jre\lib\resources.jar;D:\Software\Java\jdk1.8.0_121\jre\lib\rt.jar;D:\Software\Java\jdk1.8.0_121\jre\lib\sunrsasign.jar;D:\Software\Java\jdk1.8.0_121\jre\lib\jsse.jar;D:\Software\Java\jdk1.8.0_121\jre\lib\jce.jar;D:\Software\Java\jdk1.8.0_121\jre\lib\charsets.jar;D:\Software\Java\jdk1.8.0_121\jre\lib\jfr.jar;D:\Software\Java\jdk1.8.0_121\jre\classes, env.CMAKE_C_COMPILER=D:/Software/Cygwin/bin/gcc.exe, jackson.version=2.8.9, maven.version=3.5.0, env.TEMP=C:\Users\ZHENGT~1\AppData\Local\Temp, user.country=CN, maven.home=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\.., maven.compiler.target=1.8, env.=E:=E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool, commons-lang3.version=3.6, env.INTELLIJ IDEA=D:\Software\JetBrains\IntelliJ IDEA 193.4386.10\bin;, commons-pool2.version=2.4.2, java.vendor=Oracle Corporation, env.CLASSWORLDS_JAR="E:\Tetris\src\1_Branches\rtm_tetris_zhugan\Server\BuildTool\maven\bin\..\boot\plexus-classworlds-2.5.2.jar", protobuf.version=3.2.0, maven.compiler.source=1.8, java.specification.version=1.8, sun.arch.data.model=64, argLine=-Dfile.encoding=UTF-8}
我们可以在上述属性列表中找到这些属性:
env.PROFILE=online, profile.assembly.suffix=,
看起来"PROFILE"变量已经在环境中设置了。不过,“online”配置文件没有被激活。问题出在哪里?谢谢。
mvn -Pprofile
激活配置文件? - khmarbaise