我正按照这些说明尝试通过终端安装maven .
到目前为止我得到了这个
export M2_HOME=/user/apple/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/usr/java/jdk1.6.0_22
Run Code Online (Sandbox Code Playgroud)
这可能是一个愚蠢的问题,你去哪里找到这个?
我有一个maven程序,它编译得很好.当我运行mvn test
它时不会运行任何测试(在TESTs标题下说There are no tests to run.
).
我用一个超级简单的设置重新创建了这个问题,我将在下面包含以及运行时的输出-X
.
单元测试从eclipse运行良好(两者都使用默认的junit包,当我改为包含maven下载的junit.jar时).mvn也test-compile
正确地在test-classes下创建了类.我在OSX 10.6.7上使用Maven 3.0.2和java 1.6.0_24运行它.
这是目录结构:
/my_program/pom.xml
/my_program/src/main/java/ClassUnderTest.java
/my_program/src/test/java/ClassUnderTestTests.java
Run Code Online (Sandbox Code Playgroud)
pom.xml中:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my_group</groupId>
<artifactId>my_program</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Program</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
ClassUnderTest.java:
public class ClassUnderTest {
public int functionUnderTest(int n) {
return n;
}
}
Run Code Online (Sandbox Code Playgroud)
ClassUnderTestTests.java:
import org.junit.Assert;
import org.junit.Before; …
Run Code Online (Sandbox Code Playgroud) 当我maven install
在我的多模块maven项目上运行时,我总是得到以下输出:
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
Run Code Online (Sandbox Code Playgroud)
所以,我google了一下,但我能找到的是我必须添加:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Run Code Online (Sandbox Code Playgroud)
...到我的pom.xml.但它已经存在(在父母中pom.xml
).
配置<encoding>
maven-resources-plugin或maven-compiler-plugin也无法修复它.
所以有什么问题?
自从我更新到Maven 3后,我在每次构建时收到以下警告消息:
我怎样才能摆脱这些警告?
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for proj:id:jar:3.1
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-javadoc-plugin is missing. @ line 195, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 204, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 227, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 215, column 15
[WARNING] 'reporting.plugins.plugin.version' for org.codehaus.mojo:jdepend-maven-plugin is missing. @ line 271, column 15
[WARNING]
[WARNING] It is highly …
Run Code Online (Sandbox Code Playgroud) 尝试:
sudo apt-get install maven
Run Code Online (Sandbox Code Playgroud)
如果它适用于你,请忽略这篇文章的其余部分.
我在2013年4月开始设置我的Ubuntu 12.10,当时正常 sudo apt-get install maven
情况不适用于maven 3.
如果您想深入了解关于apt-get的ubuntu内核以及它找到可在Ubuntu上安装的应用程序列表,那么本文中的手动安装非常有用.如果你遇到与我当时使用Ubuntu 12.10相同的问题,它对于Ubuntu 15.04等更新版本的Ubuntu也可能有用.
如果您当前的ubuntu无法通过常见的"apt-get install maven"安装maven,请查看手动安装.
sudo apt-get update
sudo apt-get install maven
Run Code Online (Sandbox Code Playgroud)
如果您的ubuntu不新鲜或者您之前使用的是maven 2,请确保删除maven 2:
sudo apt-get remove maven2
Run Code Online (Sandbox Code Playgroud)
如果您的ubuntu apt-get存储库列表不是最新的,这可能很有用.
Maven 3需要设置系统,因为事实证明大多数文档都涉及如何将Maven安装到Ubuntu 12.04版或更早版本.我找到的最佳文件是:
我想出的整个过程如下:
sudo -H gedit /etc/apt/sources.list
在sources.list
文件中添加以下行:
deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu精确主要
deb-src http://ppa.launchpad.net/natecarlson/maven3/ubuntu精确主要
sudo apt-get update && sudo apt-get install maven3
sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn
注意1:命令"sudo apt-add-repository …
如何将项目的运行时依赖项复制到target/lib
文件夹中?
因为它是现在,后mvn clean install
的target
文件夹仅包含我的项目的罐子,但没有运行时依赖的.
我有一个关于IntelliJ IDEA 11的小问题.我刚刚从subversion导入了一个项目 - 它是一个maven项目.但我在maven库依赖项中遇到问题,因此我无法自动包含所有maven依赖项 - IDEA仅在我打开该类时显示依赖项错误/这就是我在这里得到的:
所以我想要自动添加所有依赖项 - 这是可能的还是我必须通过所有类文件来识别和添加maven依赖项?!
更新:在做了一些修改后,我发现了如何以某种方式解决我的问题.多数民众赞成我所做的:
但我认为逻辑上它不会包含并检查前面的新依赖项?!...在intelliJ中是否有任何设置区域 - 自动导出依赖于类路径?
mvn clean install
和之间有什么区别mvn install
?
我对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中指向的版本不同,会发生什么?
我是Intellij Idea的新手,我只是导入了一个项目pom.xml
,但是ide并没有解决maven依赖项中的任何问题.
pom.xml
在代码中导入时,依赖项中定义的任何内容都会引发错误cannot resolve symbol xxxxx
但是mvn install
会工作,我尝试Project Settings/Libraries
在.jar
文件中导入依赖项,然后它可以工作,但是ide可以解析定义的库pom.xml
吗?我不想每次都这样做.
附加信息:
IDEA版本:12.0.3,操作系统:Windows 7,重新导入不起作用,maven版本:3.0.4,Exernal Libraries下不存在maven依赖项.
idea.log中没有例外......
maven-3 ×10
maven ×9
java ×7
maven-2 ×2
apt-get ×1
build ×1
dependencies ×1
encoding ×1
junit ×1
junit4 ×1
macos ×1
maven-plugin ×1
ubuntu-16.04 ×1
ubuntu-17.04 ×1