How to install Maven on Mac OSX

After the upgrade of Mac OS X Mavericks, Maven was removed (no idea why). So, You have to install it manually.
**2.1 – Download Maven**Download the Maven, for example apache-maven-3.1.1-bin.tar.gz
. Extracts it,

tar -xvf apache-maven-3.1.1-bin.tar.gz
$pwd
/Users/mkyong/apache-maven-3.1.1

2.2 – Set Maven command in environment variable.
Update ~/. bash_profile – create this file if doesn’t exist.

$ vim ~/.bash_profile

~/.bash_profile
export M2_HOME=/Users/mkyong/apache-maven-3.1.1
export PATH=$PATH:$M2_HOME/bin

Restart the terminal. Test it.

$mvn -version

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /Users/mkyong/apache-maven-3.1.1
Java version: 1.7.0_05, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"

1.http://www.mkyong.com/maven/install-maven-on-mac-osx/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!关于你的问题,当使用Maven进行项目构建时,如果报错"Unable to find main class",通常是由于没有正确配置pom.xml文件或者项目的结构问题导致的。以下是一些可能的解决方案: 1. 确保pom.xml中正确配置了mainClass。在`<build>`标签下添加以下内容: ```xml <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.example.MainClass</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> ``` 将`com.example.MainClass`替换为你的主类名称。 2. 确保项目的源代码结构符合Maven的默认约定。Maven默认将源代码放置在`src/main/java`目录下,确保你的主类位于正确的位置。如果你的项目结构不同,可以在pom.xml中进行配置。例如,如果你的主类位于`src/main/com/example/MainClass.java`,需要在pom.xml中添加以下内容: ```xml <build> <sourceDirectory>src/main/</sourceDirectory> </build> ``` 3. 如果你使用的是可执行的JAR包,确保在pom.xml中正确配置了maven-shade-plugin插件。在`<plugins>`标签下添加以下内容: ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.4</version> <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.example.MainClass</mainClass> </transformer> </transformers> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> ``` 同样,将`com.example.MainClass`替换为你的主类名称。 4. 如果上述方法都没有解决问题,可能是由于IDE的缓存或构建配置问题。可以尝试清理项目并重新构建。如果使用的是IntelliJ IDEA等IDE,可以尝试重新导入项目或者重建Maven项目。 希望这些解决方案能够帮助你解决问题!如果还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值