maven编译时错误:无效的目标发行版
maven配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>Tools</groupId> <artifactId>Tools</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.1</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> <packaging>jar</packaging> </project>
然后执行命令打包
- mvn assembly:assembly
完成之后查看target目录就可以看见该jar包了
## 2.Fatal error compiling: 无效的目标版本: 1.7 -> [Help 1]
因为是在cmd中执行,然后maven依赖jdk,我的环境变量中将JAVA_HOME写死,指导了jdk1.6版本。而这个项目需要1.7版本,在POM文件的编译插件中
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
将版本设置为1.7就会报上面的错误。重新指定环境变量JAVA_HOME指到支持1.7以上的JDK就可以了