我对maven不太熟悉,在尝试使用多模块项目时,我开始想知道如何为父maven pom中的所有子模块指定java版本.直到今天我才使用:
<properties>
<java.version>1.8</java.version>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是在研究时我发现你也可以在maven编译器插件中指定java版本,就像那样:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
然后将其包装到插件管理标签中以启用子poms的使用.所以第一个问题是在属性和maven编译器插件中设置java版本有什么区别?
我找不到明确的答案,但在研究过程中我发现你也可以用这种方式指定java版本:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
这表明编译器插件就在那里,即使我没有明确声明它.运行mvn包输出
maven-compiler-plugin:3.1:compile (default-compile) @ testproj ---
Run Code Online (Sandbox Code Playgroud)
和其他一些我没有声明的插件.那些插件默认是隐藏的maven pom的一部分吗?在属性和maven插件配置元素中设置源/目标是否有任何差异?
还有一些其他问题 - 应该采用哪种方式(以及何时不相等)?哪一个最适合多模块项目,如果在pom中指定的java版本与JAVA_HOME中指向的版本不同,会发生什么?
我正在使用Maven 3.0.5和Spring Tool Source 3.2并安装了Maven插件.当我尝试'Run As ---> Maven install'时,我收到以下错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring Social Twitter4J Sample 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.apache.maven.plugins:maven-war-plugin:jar:2.1.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.apache.maven.plugins:maven-install-plugin:jar:2.3.1 is invalid, transitive dependencies (if any) will not …Run Code Online (Sandbox Code Playgroud) 截至今天,我的maven编译失败了.
[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO] at java.lang.String.<init>(String.java:203)
[INFO] at java.lang.String.substring(String.java:1877)
Run Code Online (Sandbox Code Playgroud)
[错误]内存不足; 要增加内存量,请在启动时使用-Xmx标志(java -Xmx128M ...)
截至昨天,我已成功运行maven编译.
截至今天,我刚刚把我的堆增加到3 GB.另外,我只更改了2-3行代码,所以我不明白这个"内存不足"的错误.
vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m
Run Code Online (Sandbox Code Playgroud)
编辑:我通过更改失败的模块的pom.xml尝试了海报的评论.但我得到了相同的maven构建错误.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>1024m</meminitial>
<maxmem>2024m</maxmem>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 试图src/main/resources/scripts/从我的构建中驱逐一个文件夹,但以下内容不起作用:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>src/main/resources/scripts/</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<excludes>
<exclude>src/main/resources/scripts/</exclude>
</excludes>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一个maven项目分叉并从git repo克隆到我的eclipse上.它建立在Java 8之上.我做的第一件事是执行a
mvn clean install
Run Code Online (Sandbox Code Playgroud)
但我收到以下失败消息:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven ---
[INFO] Deleting /Users/vshukla/git/Prism/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not …Run Code Online (Sandbox Code Playgroud) 我正在使用maven和java-9构建我的项目.我在我的pom.xml文件中添加了:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.xml.bind</arg>
</compilerArgs>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,为了运行应用程序,我必须像这样运行它:
java -jar --add-modules java.xml.bind my-app.jar
Run Code Online (Sandbox Code Playgroud)
有没有办法构建应用程序,从命令行运行而不是--add-modules java.xml.bindjava命令行参数?
我有一个使用aspectj-compiler-plugin的maven项目.我使用intertype声明,因此在我的Java代码中引用了Aspect代码.因此,maven-compiler-plugin无法编译,因为它不编译方面代码.
我的问题是:如何禁止maven-compiler-plugin运行,因为它没有做任何有用的事情?
我有几种方法可以让这个项目编译,但它们是次优的:
我试图从Spring-boot开始,在Intellij中使用Maven请帮助我我收到错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag: --release -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
我的pom.xml是:
<?xml version="1.0" encoding="UTF-8"?> <project …Run Code Online (Sandbox Code Playgroud) 昨天我在Tomcat 8上部署我的Java 8 webapp后遇到了一个有趣的问题.我不想如何解决这个问题,而是更了解为什么会发生这种情况.但是,让我们从头开始.
我有两个类定义如下:
Foo.java
package package1;
abstract class Foo {
public String getFoo() {
return "foo";
}
}
Run Code Online (Sandbox Code Playgroud)
Bar.java
package package1;
public class Bar extends Foo {
public String getBar() {
return "bar";
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,它们在同一个包中,并最终在同一个jar中,我们称之为commons.jar.这个jar是我的webapp的依赖(即在我的webapp的pom.xml中被定义为依赖).
在我的webapp中,有一段代码可以:
package package2;
public class Something {
...
Bar[] sortedBars = bars.stream()
.sorted(Comparator.comparing(Bar::getBar)
.thenComparing(Bar::getFoo))
.toArray(Bar[]::new);
...
}
Run Code Online (Sandbox Code Playgroud)
当它被执行时,我得到:
java.lang.IllegalAccessError: tried to access class package1.Foo from class package2.Something
Run Code Online (Sandbox Code Playgroud)
玩耍和试验我能够通过三种方式避免错误:
将Foo类更改为public而不是package-private;
将Something类的包更改为"package1"(即字面上与Foo和Bar类相同,但物理上不同的是webapp中定义的Something类);
在执行违规代码之前强制加载Foo:
try {
Class<?> fooClass = Class.forName("package1.Foo");
} …Run Code Online (Sandbox Code Playgroud)即使我只改变了我的一个课程,Maven总是重新编译所有课程.我使用这个插件配置:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<staleMillis>1</slateMillis>
<useIncrementalCompilation>true</useIncrementalCompilation>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
出现这种情况有mvn compile,mvn package和mvn install.
当然,如果您有10-15个文件,这不是问题.但是,我有超过一千个源文件,需要花费很多时间.
Maven编译器插件是否有一些隐藏设置来重新编译修改后的文件?有没有解决方法?