MacOS搭建JavaWeb环境记录

时间:2022-01-19 13:17:30

MacOS搭建JavaWeb环境

Windows

MacOS

mac版本下载地址

jdk

jdk

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

eclipse

eclipse

http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR1/eclipse-jee-kepler-SR1-macosx-cocoa-x86_64.tar.gz

tomcat

tomcat

http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.68/bin/apache-tomcat-7.0.68.zip

maven

maven

http://mirror.bit.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

mysql

mysql

http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-osx10.11-x86_64.dmg

Navicate

MySQLworkbench

http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-6.3.6-osx-x86_64.dmg

SqlDeveloper

Toad

AppStore

ultraedit

MacVim/Emacs

https://emacsformacosx.com/emacs-builds/Emacs-24.5-1-universal.dmg

XFtp

FileZilla

AppStore

一、jdk

1.1 安装

查看是否安装成功,在终端输入

java -version

成功如下图:

MacOS搭建JavaWeb环境记录

1.2 配置

sudo vi /etc/profile

配置内容如下:

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home"
CLASS_PATH="$JAVA_HOME/lib"
PATH=".;$PATH:$JAVA_HOME/bin"

验证:

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

二、maven

2.1  解压到/usr/local

cd /usr/loacl
sudo tar -xvf ~/Downloads/apache-maven-3.3.9-bin.tar

2.2  配置环境

参考http://maven.apache.org/install.html

 $ vi ~/.bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
MAVEN_HOME=/usr/local/apache-maven-3.3.9
PATH=$PATH:$MAVEN_HOME/bin

export MAVEN_HOME
export PATH

$ source ~/.bash_profile

*最开始没有加入第一行,查看版本时报错:

$ mvn -version
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

错误的原因是我的JAVA_HOME配置在/etc/profile中的,这里在.bash_profile中也加上JAVA_HOME的路径即可。如下

$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/local/apache-maven-3.3.9
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"

2.3 配置本地资源路径

打开conf中的setting.xml,添加自定义资源路径,如下

<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">/Users/Bdong/.m2/repository</span><span style="font-family: Arial, Helvetica, sans-serif;"></localRepository></span>

*之前错误的将路径配置到/usr/local/reposotory里,无法下载,改回本用户路径就好了

2.4 配置eclipse插件

*eclipse中Help->Eclipse Marketplace搜索关键字maven到插件Maven Integration for Eclipse ,遇到如下错误:

Cannot complete the install because one or more required items could not be found.   Software being installed: m2e - Maven Integration for Eclipse (includes Incubating components) 1.6.2.20150902-0002 (org.eclipse.m2e.feature.feature.group 1.6.2.20150902-0

网上查了资料

少了maven依赖的eclipse插件,解决方法如下:

直接在线安装maven2 会出现依赖插件找不到的问题,无法安装。必须先安装gef 插件后才能安装m2eclipse-core 插件,然而安装m2eclipse-extras 插件又依赖subclipse 插件。所以,三个插件的正确的安装顺序是:gef插件 》subclipse插件 》m2eclipse插件。 
m2eclipse-core插件 ——依赖——>gef插件 
m2eclipse-extras插件 ——依赖——>subclipse插件

启动eclipse,点击window——>preferences——>install/update——>available software sites,点击Add
添加如下信息:

GEF             http://download.eclipse.org/tools/gef/updates/interim/
Subclipse      http://subclipse.tigris.org/update_1.6.x

下载这几个插件
然后再重新安装maven插件 

m2e http://download.eclipse.org/technology/m2e/milestones/1.4 (以低版本替代)


其它省略的软件基本属于直接安装的,无需记录

参考资料:

[1]http://blog.sina.com.cn/s/blog_55b1b0d50100ynjg.html

[2]http://www.cnblogs.com/jerome-rong/archive/2012/12/18/2823242.html

[3]http://peirenlei.iteye.com/blog/790331

[4]http://blog.csdn.net/wode_dream/article/details/38052639