本文目录一览:
如何在maven pom.xml文件中设置Java编译器版本
1,生成3个目录/lib,/conf,/bin目录
2,把所有的jar目录编译、拷贝到/lib目录(包括maven的jar包和lib目录下的jar,以及编译的jar包)
3,把所有的启动脚本从工程根目录拷贝到/bin目录
4,把所有的配置文件从src/main/resources拷贝到/conf
pom.xml 配置
project xmlns="" xmlns:xsi=""
xsi:schemaLocation=" "
modelVersion4.0.0/modelVersion
groupIdtest/groupId
artifactIdtest.common/artifactId
version0.0.1-SNAPSHOT/version
packagingjar/packaging
nametest.common/name
url;/url
properties
project.build.sourceEncodingUTF-8/project.build.sourceEncoding
/properties
dependencies
!-- 这里省略n行 --
/dependencies
build
sourceDirectorysrc/main/java/sourceDirectory
resources
!-- 把src/main/resources目录下所有的文件拷贝到conf目录中 --
resource
directorysrc/main/resources/directory
targetPath${project.build.directory}/conf/targetPath
/resource
!-- 把lib目录下所有的文件拷贝到lib目录中
(可能有些jar包没有办法在maven中找到,需要放在lib目录中) --
resource
directorylib/directory
targetPath${project.build.directory}/lib/targetPath
/resource
!-- 把放在根目录下的脚本文件.sh,.bat拷贝到bin目录中 --
resource
directory./directory
includes
include**/*.sh/include
include**/*.bat/include
/includes
targetPath${project.build.directory}/bin/targetPath
/resource
/resources
plugins
!-- 用于编译的plugin --
plugin
groupIdorg.apache.maven.plugins/groupId
artifactIdmaven-compiler-plugin/artifactId
version3.1/version
configuration
forktrue/fork
defaultLibBundleDirlib/defaultLibBundleDir
source1.7/source
target1.7/target
encodingUTF-8/encoding
!-- 如果配置了JAVA_HOME,下面应该可以不用配 --
executableC:\Program Files (x86)\Java\jdk1.8.0_91\bin\javac.exe/executable
/configuration
/plugin
!-- 用于生成jar包的plugin --
plugin
groupIdorg.apache.maven.plugins/groupId
artifactIdmaven-jar-plugin/artifactId
version2.6/version
configuration
!-- 把生成的jar包放在lib目录下(和其他所有jar包一起) --
outputDirectory${project.build.directory}/lib/outputDirectory
archive
manifest
addClasspathtrue/addClasspath
classpathPrefixlib//classpathPrefix
/manifest
/archive
excludes
!-- 排除掉一些文件,不要放到jar包中,
这里是为了排除掉src/main/resources中的文件(它们应该放到conf目录)
这里只能指定要排除的目标文件,而不能指定源文件,虽然不够完美,但是基本能达到目的。 --
exclude*.xml/exclude
exclude*.properties/exclude
/excludes
/configuration
/plugin
!-- 用于拷贝maven依赖的plugin --
plugin
groupIdorg.apache.maven.plugins/groupId
artifactIdmaven-dependency-plugin/artifactId
version2.10/version
executions
execution
idcopy-dependencies/id
phasepackage/phase
goals
goalcopy-dependencies/goal
/goals
configuration
!-- 把依赖的所有maven jar包拷贝到lib目录中(这样所有的jar包都在lib目录中) --
outputDirectory${project.build.directory}/lib/outputDirectory
/configuration
/execution
/executions
/plugin
!-- 用于拷贝resource的plugin --
plugin
groupIdorg.apache.maven.plugins/groupId
artifactIdmaven-resources-plugin/artifactId
version2.7/version
configuration
encodingUTF-8/encoding
/configuration
/plugin
!-- 配置生成源代码jar的plugin --
plugin
artifactIdmaven-source-plugin/artifactId
version2.4/version
configuration
attachtrue/attach
encodingUTF-8/encoding
!-- 配置源代码jar文件的存放路径,和其他jar文件一起放在lib目录 --
outputDirectory${project.build.directory}/lib/outputDirectory
/configuration
executions
execution
phasecompile/phase
goals
goaljar/goal
/goals
/execution
/executions
/plugin
/plugins
/build
/project
然后执行maven package打包。如果是eclipse,在Project Explorer- Run As – Maven Build… –在Goals中输入package,点Run进行编译。
如何修改maven的默认jdk版本
修改maven默认的jdk版本,想改彻底需要在maven的全局配文件(settings.xml)增加以下信息:
在profiles 节点下增加:
profile
idjdk-1.6/id
activation
activeByDefaulttrue/activeByDefault
jdk1.6/jdk
/activation
properties
maven.compiler.source1.6/maven.compiler.source
maven.compiler.target1.6/maven.compiler.target
maven.compiler.compilerVersion1.6/maven.compiler.compilerVersion
/properties
/profile
这里的jdk版本可以任意改。
如何修改Maven的JDK版本
方式1、修改maven全局jdk
修改 安装目录\maven2\conf\settings.xml
Xml代码
profiles
profile
idjdk-1.6/id
activation
activeByDefaulttrue/activeByDefault
jdk1.6/jdk
/activation
properties
maven.compiler.source1.6/maven.compiler.source
maven.compiler.target1.6/maven.compiler.target
maven.compiler.compilerVersion1.6/maven.compiler.compilerVersion
/properties
/profile
/profiles
方式2、修改项目pom.xml
Xml代码
build
plugins
plugin
groupIdorg.apache.maven.plugins/groupId
artifactIdmaven-compiler-plugin/artifactId
version2.0.2/version
configuration
source1.6/source
target1.6/target
/configuration
/plugin
/plugins
/build