首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >-source给出错误: Maven 1.5中不支持使用资源尝试

-source给出错误: Maven 1.5中不支持使用资源尝试
EN

Stack Overflow用户
提问于 2013-06-25 22:26:42
回答 1查看 18.7K关注 0票数 14

当我尝试使用IntelliJ 12.1.4和Java7在Maven3.0.5中创建jar时,我得到了错误。我可以通过集成开发环境运行项目,但当我试图打包它时,我得到了以下错误。

我的POM的相关部分(由Sonatype摘自Maven By Example )是:

代码语言:javascript
运行
复制
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>jar-with-dependencies</descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

错误是:

代码语言:javascript
运行
复制
[ERROR] ...[33,55] error: diamond operator is not supported in -source 1.5
[ERROR] ...[207,7] error: try-with-resources is not supported in -source 1.5
[ERROR] ...[73,52] error: diamond operator is not supported in -source 1.5
[ERROR] ...[129,40] error: multi-catch statement is not supported in -source 1.5
[ERROR] ...[44,6] error: try-with-resources is not supported in -source 1.5
[ERROR] ...[28,39] error: diamond operator is not supported in -source 1.5
[ERROR] ...[31,7] error: try-with-resources is not supported in -source 1.5
[ERROR] ...[38,6] error: try-with-resources is not supported in -source 1.5
[ERROR] ...[34,41] error: diamond operator is not supported in -source 1.5
[ERROR] ...[77,43] error: diamond operator is not supported in -source 1.5
[ERROR] ...[84,6] error: try-with-resources is not supported in -source 1.5
[ERROR] ...[281,38] error: diamond operator is not supported in -source 1.5
[ERROR] ...[13,55] error: diamond operator is not supported in -source 1.5
[ERROR] ...[155,7] error: try-with-resources is not supported in -source 1.5

如何让maven使用源码1.7?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-25 22:26:42

要回答第一部分,请将以下行添加到POM以设置语言级别

代码语言:javascript
运行
复制
 <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

添加这些行之后,您就可以成功地构建您的jar了,尽管当您运行它时,您的jar会给出一个no main manifest attribute错误。

这可以通过像java -cp app.jar com.somepackage.SomeClass这样运行来修复

或者,要纠正这一点并生成可执行的jar,请使您的pom看起来像这样。

代码语言:javascript
运行
复制
 <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>fully.qualified.main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

此pom通过将依赖项复制到构建目录,然后使用包含的库创建jar,从而克服了jar-with-dependencies descriptorRef的一些问题。

感谢@André Aronsen提供的pom解决方案。

关于没有主要的清单错误,有很多关于这个问题的帖子,一些解决方案有效,一些不起作用。这个解决方案对我有效,所以我把它包含在这篇文章中作为补充。

使用Java7、Maven3.0.5和JetBrains IntelliJ IDEA 12.1.4旗舰版进行了测试。

票数 45
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17300008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档