为什么要使用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. OpenGL学习——基本概念和坐标变换

    基本概念 基本功能:几何图形.变换.着色.光照.贴图 高级功能:曲面图元.光栅操作.景深.shader编程   状态机 先设置状态参数:多边形.顶点列表.填充颜色.纹理.混合模式.坐标系 再调用绘图指 ...

  2. redo文件三

    switch logfile是一种昂贵的操作,在进行日志切换的时候,是不允许生成新的redo信息 在前台进程生成redo日志信息的时候,此时redo buffer已经分配了空间,并且在当前的redo日 ...

  3. 解开发者之痛:中国移动MySQL数据库优化最佳实践(转)

    开源数据库MySQL比较容易碰到性能瓶颈,为此经常需要对MySQL数据库进行优化,而MySQL数据库优化需要运维DBA与相关开发共同参与,其中MySQL参数及服务器配置优化主要由运维DBA完成,开发则 ...

  4. 【转】浅析C语言的非局部跳转:setjmp和longjmp

    转自 http://www.cnblogs.com/lienhua34/archive/2012/04/22/2464859.html C语言中有一个goto语句,其可以结合标号实现函数内部的任意跳转 ...

  5. Java缓存学习之二:浏览器缓存机制

    浏览器端的九种缓存机制介绍 浏览器缓存是浏览器端保存数据用于快速读取或避免重复资源请求的优化机制,有效的缓存使用可以避免重复的网络请求和浏览器快速地读取本地数据,整体上加速网页展示给用户.浏览器端缓存 ...

  6. hibernate 打印sql和参数的配置

    1.配置spring-hiberbate.xml:<prop key="hibernate.show_sql">true</prop>--强制打印sql 不 ...

  7. POJ 1679 The Unique MST (最小生成树)

    The Unique MST 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/J Description Given a conn ...

  8. JSF 2 outputText example

    In JSF 2.0 web application, "h:outputText" tag is the most common used tag to display plai ...

  9. AutoCAD.NET二次开发:扩展数据之XData

    结果缓存——ResultBuffer 结果缓存即 Autodesk.AutoCAD.DatabaseServices.ResultBuffer 类型,使用 ResultBuffer 对象时需要提供一个 ...

  10. php-fpm 启动不了 libiconv.so.2找不到

    service php-fpm start  Starting php-fpm /alidata/server/php/sbin/php-fpm: error while loading shared ...