为什么要使用Maven

  • 摘自百度百科的介绍

Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。
Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司项目采用 Maven 的比例在持续增长。

  • 我为什么要使用Maven

作为一个Java/Scala的新人,我第一次使用Maven的时候,并不太了解Maven的什么,我所想的只是在我的Scala项目中引入一个画图表的库,后来我的Github找到了一个我想要的库。在我想引用这个库,潜意识里我就开始寻找这个库的Jar包,最后用Maven顺利解决我的项目的依赖问题。

Scala IDE Maven配置(使用开源中国的Maven库)

  • 为什么要重新配置Maven

因为Maven默认用的是外国的库,国外的服务器在大陆访问要么是连接不上要么是连接上了乌龟那么慢,为了不折腾我脆弱的心灵还是用国内的Maven库吧。

  • Scala IDE Maven配置

打开Maven配置:Window->Perferences->Maven->User Settings

默认的Settings路径是:C:\Users\Administrator\.m2\Settings 当然你也可以把路径更改到你想要放的地方

我的Maven配置,参考开源中国 Maven 库使用帮助 传送门

<?xml version="1.0" encoding="UTF-8"?>

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. --> <!-- | This is the configuration file for Maven. It can be specified at two
levels: | | 1. User Level. This settings.xml file provides configuration
for a single user, | and is normally provided in ${user.home}/.m2/settings.xml.
| | NOTE: This location can be overridden with the CLI option: | | -s /path/to/user/settings.xml
| | 2. Global Level. This settings.xml file provides configuration for all
Maven | users on a machine (assuming they're all using the same Maven | installation).
It's normally provided in | ${maven.home}/conf/settings.xml. | | NOTE: This
location can be overridden with the CLI option: | | -gs /path/to/global/settings.xml
| | The sections in this sample file are intended to give you a running start
at | getting the most out of your Maven installation. Where appropriate,
the default | values (values used when the setting is not specified) are
provided. | | --> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository | The path to the local repository maven will use to
store artifacts. | | Default: ~/.m2/repository --> <localRepository>E:\maven\repo</localRepository> <!-- interactiveMode | This will determine whether maven prompts you when
it needs input. If set to false, | maven will use a sensible default value,
perhaps based on some other setting, for | the parameter in question. | |
Default: true <interactiveMode>true</interactiveMode> --> <!-- offline | Determines whether maven should attempt to connect to the
network when executing a build. | This will have an effect on artifact downloads,
artifact deployment, and others. |localRepository | Default: false <offline>false</offline> --> <!-- pluginGroups | This is a list of additional group identifiers that
will be searched when resolving plugins by their prefix, i.e. | when invoking
a command line like "mvn prefix:goal". Maven will automatically add the group
identifiers | "org.apache.maven.plugins" and "org.codehaus.mojo" if these
are not already contained in the list. | --> <pluginGroups>
<!-- pluginGroup | Specifies a further group identifier to use for plugin
lookup. <pluginGroup>com.your.plugins</pluginGroup> -->
</pluginGroups> <!-- proxies | This is a list of proxies which can be used on this machine
to connect to the network. | Unless otherwise specified (by system property
or command-line switch), the first proxy | specification in this list marked
as active will be used. | --> <proxies>
<!-- proxy | Specification for one proxy, to be used in connecting to the
network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol>
<username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host>
<port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> -->
</proxies> <!-- servers | This is a list of authentication profiles, keyed by the server-id
used within the system. | Authentication profiles can be used whenever maven
must make a connection to a remote server. | --> <servers>
<!-- server | Specifies the authentication information to use when connecting
to a particular server, identified by | a unique name within the system (referred
to by the 'id' attribute below). | | NOTE: You should either specify username/password
OR privateKey/passphrase, since these pairings are | used together. | <server>
<id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password>
</server> --> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id>
<privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave
empty if not used.</passphrase> </server> -->
</servers> <!-- mirrors | This is a list of mirrors to be used in downloading artifacts
from remote repositories. | | It works like this: a POM may declare a repository
to use in resolving certain artifacts. | However, this repository may have
problems with heavy traffic at times, so people have mirrored | it to several
places. | | That repository definition will have a unique id, so we can create
a mirror reference for that | repository, to be used as an alternate download
site. The mirror site will be the preferred | server for that repository.
| --> <mirrors>
<!-- mirror | Specifies a repository mirror site to use instead of a given
repository. The repository that | this mirror serves has an ID that matches
the mirrorOf element of this mirror. IDs are used | for inheritance and direct
lookup purposes, and must be unique across the set of mirrors. | -->
<mirror>
<id>nexus-osc</id>
<mirrorOf>*</mirrorOf>
<name>Nexus osc</name>
<url>http://maven.oschina.net/content/groups/public/</url>
</mirror>
</mirrors> <!-- profiles | This is a list of profiles which can be activated in a variety
of ways, and which can modify | the build process. Profiles provided in the
settings.xml are intended to provide local machine- | specific paths and
repository locations which allow the build to work in the local environment.
| | For example, if you have an integration testing plugin - like cactus
- that needs to know where | your Tomcat instance is installed, you can provide
a variable here such that the variable is | dereferenced during the build
process to configure the cactus plugin. | | As noted above, profiles can
be activated in a variety of ways. One way - the activeProfiles | section
of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular
value for the property, | or merely testing its existence. Profiles can also
be activated by JDK version prefix, where a | value of '1.4' might activate
a profile when the build is executed on a JDK version of '1.4.2_07'. | Finally,
the list of active profiles can be specified directly from the command line.
| | NOTE: For profiles defined in the settings.xml, you are restricted to
specifying only artifact | repositories, plugin repositories, and free-form
properties to be used as configuration | variables for plugins in the POM.
| | --> <profiles>
<profile>
<id>jdk1.8.0_65</id>
<activation>
<jdk>1.8.0_65</jdk>
</activation>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- activeProfiles | List of profiles that are active for all builds. |
<activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles> -->
</settings>

Maven的使用(我的使用方式~哈)

  • 查找你想要的引用的库

  1. 可以在Github或Google自己要用到的库
  2. 然后在官方库或开源的Maven库查找你所要的库 官方:传送门  开源中国:传送门(建议使用官方库搜索)
  3. 把搜索结果里的Maven依赖XML内容添加到你的pom文件的依赖标签里
  • 搜索的时候的注意事项

  1. 要对比好你要引用库的所属构件,因为搜索结果可能什么很多
  2. 还要要把你引用的库的依赖的库也一起添加到你的pom文件的依赖(我一直觉得这一步是可以自动做到的,只是我还没有学会而已)

官方搜索结果

从搜索可以看到官方的库支持很多的构建工具:Maven/Ivy/SBT

在官方的搜索结果中还会列出所搜索库的依赖库,只要点击相应的链接就可以跳转到依赖库,使用起来很方便,不用多次查找。

开源中国搜索结果

pom文件依赖配置

 
开源中国 Maven 库使用帮助 传送门

Spark之路 --- Scala IDE Maven配置(使用开源中国的Maven库)和使用的更多相关文章

  1. Maven 项目使用开源中国镜像

    从maven中央库下载jar非常缓慢甚至有时候会下载不下来. 可以采用中国的maven镜像.目前主要是 开源中国的镜像. 找到maven配置文件setting.xml,打开 中间添加开源中国的配置: ...

  2. virtenv 0.8.6 发布,虚拟桌面配置工具 - 开源中国社区

    virtenv 0.8.6 发布,虚拟桌面配置工具 - 开源中国社区 virtenv 0.8.6 发布,virtenv 是一个用 QT4 开发的应用,用来配置和启动基于 LXC 的虚拟桌面环境.该容器 ...

  3. Spark之路 --- Scala用JFreeChart画图表实例

    JFreeChart介绍 JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用 ...

  4. maven配置之:<distributionManagement>snapshot快照库和release发布库

    在使用maven过程中,我们在开发阶段经常性的会有很多公共库处于不稳定状态,随时需要修改并发布,可能一天就要发布一次,遇到bug时,甚至一天要发布N次.我们知道,maven的依赖管理是基于版本管理的, ...

  5. Ubuntu下Maven配置与Maven项目创建教程

    一. Ubuntu下Maven配置 windows下Maven配置参考http://www.cnblogs.com/LexMoon/p/JavaMaven.html ubuntu下Maven地址htt ...

  6. maven配置详解

    什么是pom?     pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的 ...

  7. 史上最强maven配置详情

    史上最强maven配置详情 优点 对第三方依赖库进行了统一的版本管理 统一了构建过程 统一了项目的目录结构 构建 清理 : mvn clear 编译 : mvn compile 测试 : mvn te ...

  8. 【maven】在idea上创建maven多模块项目

    参考:https://www.cnblogs.com/wangmingshun/p/6383576.html 一:创建父项目 (1)idea引导页 (2)创建父项目,不需要选择maven插件 (3)完 ...

  9. Spark之路 --- Windows Scala 开发环境安装配置

    JDK安装 JDK安装包下载 到Oracle官网下载JDK. 传送门 下载之前要记得勾选上同意协议然后选择相应的版本(Windows/Linux, 32/64) JDK安装及验证 按提示完成安装,安装 ...

随机推荐

  1. canvas 模拟小球上抛运动的物理效果

    最近一直想用学的canvas做一个漂亮的小应用,但是,发现事情并不是想的那么简单.比如,游戏的逼真效果,需要自己来coding…… 所以,自己又先做了一个小demo,算是体验一下亲手打造物理引擎的感觉 ...

  2. springMVC(注解版笔记)

    springMVC(注解版) 较之于非注解版本,发生一下变化: 1.配置文件需要配置的标签有: <!-- 包的扫描,此包下面的所有包都启用注解 --> <context:compon ...

  3. wuzhicms 后台登录存留时间实现方式

    在五指后台管理登录后,超过半小时不操作后台(不刷新页面或切换页面),就就会强制退出后台. 实现的思路是,在每次刷新页面都把当前时间存储下来,利用php的session机制来检测比对当前时间和数据库中存 ...

  4. MYSQL里的索引类型介绍

    首先要明白索引(index)是在存储引擎(storage engine)层面实现的,而不是在server层面.不是所有的存储引擎支持有的索引类型. 1.B-TREE 最常见的索引类型,他的思想是所有的 ...

  5. 链表回文串判断&amp;&amp;链式A+B

    有段时间没有练习了,链表回文串判断用到了栈.链式A+B将没有的项用0补充.链表有没有头节点,及结点和链表的区别,即pNode和pHead. //#include<iostream> //u ...

  6. Fast Intro To Java Programming (2)

    Java局部变量 局部变量声明在方法.构造方法或者语句块中: 局部变量在方法.构造方法.或者语句块被执行的时候创建,当它们执行完成后,变量将会被销毁: 访问修饰符不能用于局部变量: 局部变量只在声明它 ...

  7. http响应Last-Modified和ETag(转)

    基础知识 1) 什么是”Last-Modified”? 在浏览器第一次请求某一个URL时,服务器端的返回状态会是200,内容是你请求的资源,同时有一个Last-Modified的属性标记此文件在服务期 ...

  8. Linux Oracle服务启动&停止脚本与开机自启动

    在CentOS 6.3下安装完Oracle 10g R2,重开机之后,你会发现Oracle没有自行启动,这是正常的,因为在Linux下安装Oracle的确不会自行启动,必须要自行设定相关参数,首先先介 ...

  9. UVALive 7276 Wooden Signs (DP)

    Wooden Signs 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/E Description http://7xjob4. ...

  10. MSGPACK(一)

    MSGPACK跨平台的数据序列规范,为多种语言所支持.用它序列还是还原数据都异常方便. 而且它支持序列的数据格式非常之多,因为它支持的数据格式多,所以MSGPACK的第二功用:缓存. DELPHI的M ...