每天学习一个命令:pidof 查找进程 PID

pidof finds the process id’s(pids) of the names programs.

Usage

pidof [name]

Example

find chrome pid

pidof chrome
pidof -s chrome

Options:

  • -s instructs the program to only return one pid.

Extension

  • pgrep

2019-05-14 pid , netstat , command , linux

Cross-platform Softwares I am using

This post will only list cross-platform softwares I used now. Each software has its own behaviors, and binded with its own shortcut. It takes time to be familiar with it. So I decided to use only cross-platform softwares in daily life in case I have to swith my main System. But it seems fine till now. I am happy with these great softwares.

IntelliJ IDEA

DescriptionIntelliJ IDEA is a Java integrated development environment for developing computer software. It is developed by JetBrains, and is available as an Apache 2 Licensed community edition, and in a proprietary commercial edition. Both can be used for commercial development.

Open Sources Alternatives:

  • Eclipse

Chrome

DescriptionGoogle Chrome is a cross-platform web browser developed by Google. It was first released in 2008 for Microsoft Windows, and was later ported to Linux, macOS, iOS, and Android. The browser is also the main component of Chrome OS, where it serves as the platform for web apps.

Alternatives:

  • vivaldi

SmartGit

SmartGit is a Git GUI client with support for SVN, GitHub, BitBucket pull requests and comments.

WizNote

WizNote for Windows/Mac/Linux is a cross-platform cloud based note-taking client.

GoldenDict

GoldenDict is an open-source dictionary program that gives translations of words and phrases for different languages. It allows the use of several popular dictionary file formats simultaneously and without conversion. The project aims to create a feature-rich dictionary search program.

TeamViewer

[[TeamViewer]] is proprietary software for remote control, desktop sharing, online meetings, web conferencing and file transfer between computers.

pCloud

pCloud is the secure cloud storage, where you can store, share and work on all your files.

Crypt

VeraCrypt is a source-available freeware utility used for on-the-fly encryption. It can create a virtual encrypted disk within a file or encrypt a partition or the entire storage device with pre-boot authentication. VeraCrypt is a fork of the discontinued TrueCrypt project.

TagSpace

TagSpaces is an open-source data manager and file navigator. It helps organize files on local drives by adding tags to files. Users get the same user interface to manage their files on different platforms. TagSpaces is compatible with Windows, Linux, Mac, Android, iPhone, Firefox and Chrome.

Calibre

Calibre is a cross-platform open-source suite of e-book software. Calibre supports organizing existing e-books into virtual libraries, displaying, editing, creating and converting e-books, as well as syncing e-books with a variety of e-readers. Editing books is supported for EPUB and AZW3 formats.

Telegram

Telegram is a cloud-based instant messaging and voice over IP service developed by Telegram Messenger LLP, a privately held company registered in London, United Kingdom, founded by the Russian entrepreneur Pavel Durov and his brother Nikolai.

balenaEtcher

[[balenaEtcher]] is a powerful OS image flasher built with web technologies to ensure flashing an SDCard or USB drive is a pleasant and safe experience.


2019-05-10 applications , apps

使用 Stylus 扩展自定义页面样式

有油猴脚本可以用来修改网页页面,那么相应的也能通过挂载自己的定义的 CSS 来实现对页面的修改。

如果有了这样的概念,那么可以在页面做到,完全修改页面显示的样式,增加背景,移除广告等等事情。

installation

安装扩展

CSS 样式

从该站点寻找可用的样式

InoReader

  • https://userstyles.org/styles/119240/inoreader-countrystyle-flat-ui-remove-ads

reference


2019-05-08 stylus , css , chrome , firefox , extension

Ruby 国内镜像

Update ruby

gem update --system
gem -v
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l

确保只有 gems.ruby-china.com

Bundler

bundle config mirror.https://rubygems.org https://gems.ruby-china.com
bundle install

reference


2019-05-02 ruby , source , bundler , jekyll

威联通折腾篇十五:rtorrent-Pro 使用

QNAP CLUB 中淘到很多不错的应用,rtorrent-Pro 就是一款,现在作者升级了 rtorrent-pro 付费 15 欧元。这又是一款 BT 下载工具,界面非常美观。

rtorrent development for QNAP was started in 2008. Today after 10yrs from its 1st build, we provide you best Torrent app ever. rtorrent is an high performance and extra featured bittorrent client combined with simple and elegant user interface. rtorrent differentiates itself from other implementations by transferring data directly between file pages mapped to memory by the mmap() function and the network stack. On high-bandwidth connections, it claims to be able to seed at 3 times the speed of the official client. We strive to make rtorrent the best torrent client you could ever want!

rtorrent ui

支持的 QNAP 型号

  • armv7l - ARM processors: TS-x28/x31P/x31P2/x41 and more…
  • x86_64 - Intel/AMD64 CPU: TS-x51 and all higher (x53/61/63/70/71/73/77/78/80/82/88…)

如果不确定自己的 QNAP 型号,登录后台运行 uname -m 输出 CPU 架构如果是上面提到的两个就是支持的。

Installation

安装非常简单,下载应用,在后台上传安装即可。安装后默认的用户名是:rtorrent 密码是:admin.

rtorrent pro splash screen

重启,启动,暂停的使用:

/etc/init.d/rtorrent.sh [start|stop|restart]

Things to do

在安装完毕之后,第一件事情就是更改密码。

用新密码登录进去之后进行配置,首先熟悉配置文件的地址。

Config

配置文件地址:

vi /share/CACHEDEV1_DATA/.qpkg/rtorrent/etc/rtorrent.conf

需要注意的是如果之前安装过其他 BT 下载工具,比如 Transmission 之类,可能会造成端口冲突 (DHT 端口),需要手工调整一下端口设置。

rtorrent 用到的端口:

  • 6881 DHT, 可在配置文件修改
  • 42000 连入端口
  • 19000

Change Paths

注意到该路径,rtorrent 相关的内容都安装在了该路径中。安装完毕之后 rtorrent 会在 Download 目录下创建名为 rtorrent 的文件夹,并且创建软链接 /share/Rdownload,rtorrent 下载的内容都会在该目录中。

In stock QNAP applications, a default Download share is used to save downloaded data from the Internet. Download share location is always static and only on the first initiated disk volume. In the default configuration, Rtorrent also uses the Download network share.

可以自定义 Rtorrent 存储的路径,创建共享文件夹名为 Rdownload,指定一块硬盘,当创建共享文件夹时,记得关闭 Rtorrent-Pro,创建成功后再启动。这样 rtorrent-Pro 就会使用新的路径。

Watch 监控目录

Transmission 之前的文章 也提到过监控某个文件夹,一旦有文件新加进去自动下载。

rtorrent 同样可以实现,默认的配置已经有配置,如果想要更加详细的了解,可以参考这里

Schedule 的语法:

# Schedule syntax: id,start,interval,command call cmd every interval seconds

比如:

schedule = watch_directory_1,20,10,"load.start=/downloads/watched/*.torrent"

说明:

用简短的一句话来总结上面的配置含义就是,定义了一个定时器,名叫 watch_directory_1, rTorrent 启动后 20 秒开始,每隔 10 秒执行一次命令,这个命令是从给定的目录中加载 torrent 文件。

  • schedule 的语法用逗号分隔四段,分别是 ID,启动,间隔时间,执行的命令
  • id 可以自行定义
  • start,rTorrent 启动后多久开始执行
  • interval ,间隔多长时间执行,如果是 0 则表示执行一次
  • load.start 表示从给定的目录(该目录必须要存在)加载 torrent 文件,这个地方除了 load.start 还可以用
    • load.start_verbose = file
    • load.verbose = file, verbose 会在终端将任何错误打印出来
    • load.normal

rtorrent 配置说明

# Maximum and minimum number of peers to connect to per torrent.
# throttle.min_peers.normal.set = 40
# throttle.max_peers.normal.set = 100
# 最小允许的 peer
min_peers = 40
# 最大允许 peer
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
# throttle.min_peers.seed.set = 25
# throttle.max_peers.seed.set = 60
min_peers_seed = 10
max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
# throttle.max_uploads.set = 30
# 最大同时上传数
max_uploads = 10

# Global upload and download rate in KiB. "0" for unlimited.
# throttle.global_up.max_rate.set_kb = 0
# throttle.global_down.max_rate.set_kb = 0
# 最大下载速度
download_rate = 1024
# 最大上传速度
upload_rate = 512

# tracker_numwant = -1
#trackers.numwant.set = -1

# Max mapped memory
# nb does not refer to physical memory
# max_memory_usage = 768M
pieces.memory.max.set = 1024M

# Max number of files to keep open simultaneously
# max_open_files = 65536
#network.max_open_files.set = 1024

# max_open_http = 48
#network.http.max_open.set = 48

# Default directory to save the downloaded torrents.
# directory.default.set = /share/Rdownload/downloads/
# 下载目录
directory = /share/Rdownload/downloads/

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
# session.path.set = /share/Rdownload/session
# 下载历史,包括进度信息,DHT 节点缓存
session = /share/Rdownload/session

# Schedule syntax: id,start,interval,command call cmd every interval seconds,
#                  starting from start.
# An interval of zero calls the task once while a start of zero calls it immediately.
# Start and interval may optionally use a time format dd:hh:mm:ss
# e.g. to start a task every day at 18:00, use 18:00:00,24:00:00.
# Commands: stop_untied =, close_untied =, remove_untied =
# Stop, Close or Remove the torrents that are tied to filenames that have been deleted

# Watch a directory for new torrents, and stop those that have been
# deleted.
# 将 torrent 文件放到该目录自动下载
schedule = watch_directory,10,10,load_start=/share/Rdownload/watch/*.torrent
# 将 torrent 文件移走停止下载
#schedule = untied_directory,10,10,stop_untied=

# Close torrents when diskspace is low.
# 当硬盘空间不足停止所有下载
schedule = low_diskspace,5,60,close_low_diskspace=1000M

# Stop torrents when reaching upload ratio in percent, when also reaching
# total upload in bytes, or when reaching final upload ratio in percent
# Example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
# 在总上传量达到 200M 的情况下上传 / 下载率达到 200%,
# 或者在总上传量不足 200M 情况下上传 / 下载率达到 2000%, 则停止上传
#schedule = ratio,60,60,stop_on_ratio=200,200M,2000
#ratio.enable=
#ratio.min.set=500
#ratio.max.set=2000
#ratio.upload.set=200M
#method.set = group.seeding.ratio.command, d.close=

# Port range to use for listening.
# network.port_range.set = 6890-6999
# bt 监听端口
port_range = 42000-42000

# Start opening ports at a random position within the port range.
# network.port_random.set = no
# 是否随机从上面的端口中选择
port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
# pieces.hash.on_completion.set = yes
check_hash = yes

# Set whether the client should try to connect to UDP trackers.
# use_udp_trackers = yes
trackers.use_udp.set = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Remove a scheduled event
# schedule_remove = "ip_tick"


# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
# dht.mode.set = auto
dht = auto

# UDP port to use for DHT.
# DHT 的 UDP 端口
# dht_port = 6881
dht.port.set = 6882

# Enable peer exchange (for torrents not marked private)
#
# protocol.pex.set = yes
protocol.pex.set = yes
#peer_exchange = yes

# network.scgi.open_port = 127.0.0.1:5000
scgi_port = 127.0.0.1:19000
#scgi_local = /var/run/rtorrent-rpc.socket

network.xmlrpc.dialect.set = i8
#xmlrpc_dialect=i8
encoding_list = UTF-8

以上配置文件非全部,如果要应用到真实环境,请拷贝完整的配置,以上只作为演示和注释使用。

Other

BT 下载的工具有很多,qBittorrent,Transmission,rtorrent, uTorrent,等等,非常多,wiki 有一张非常详细的对比图,在不同系统上都有着各自的最佳选择。对占用资源,下载效率的测试还没有来得及验证,等使用一段时间后再来更新吧。

Android Client

记得启用之后可以使用 [[Transdroid]] Android 客户端来管理 rtorrent-pro. 可以从 Google Play Store 下载,或者从官网:

安装之后在设置中添加 Server,名字,服务器类型,IP,HOST NAME,User name, password 没啥好说,这里的用户名和密码和界面上的用户名和密码一致。

在高级设置中,记得将 Port Number 设置为 6009, 或者使用 Use SSL 的话,输入 6008.

详细的每一步指导看这里

reference


2019-05-02 qnap , nas , bt , pt

威联通折腾篇十三:替换默认 shell 为 zsh

默认 SSH 登录到 QNAP 的 login shell 可以通过 echo $SHELL 来查看到是

/bin/sh

默认的这个 bash 是 QNAP 自带的

/bin/sh --version
GNU bash, version 3.2.57(1)-release (x86_64-QNAP-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

也是一个相对比较简陋的版本,自动补全很难用,也没有语法高亮。所以想能不能把 QNAP 自带的 shell 换成日常使用的 ZSH,QNAP 本质上就是一个 Linux,所以理所当然的应该是可行的。

Installation

首先要要解决的问题是安装问题,普通的 Linux 发行版直接使用一行命令就可以完成,QNAP 可以使用 QNAP club 别人提供的版本,直接安装即可

wget https://cdn.qnapclub.eu/qpkg_artifacts/ZSH_5.7.0_x86_64/ZSH_5.7.0_x86_64.qpkg
sh ZSH_5.7.0_x86_64.qpkg

如果你参考过我之前的文章 你应该知道添加了 QNAP Club 的地址可以直接在 App Center 中直接搜索下载。

安装好之后,默认的 zsh 会安装到

/opt/ZSH

Usage

SSH 登陆 QNAP 之后直接在终端输入 zsh 即可进入 zsh。

ZSH 一些强大的功能:

  • 强大的补全功能
  • 错误检查以及自动更正
  • 命令别名、路径别名
  • 强大的提示信息

默认的配置在 /opt/ZSH 中,可以自己做一些微调,比如

vi /opt/ZSH/zshrc.zsh-template
or
vi /root/.zshrc

修改主题

ZSH_THEME="agnoster"

等等。

Tips

如果在使用过程中发现,delete功能异常,比如delete虽然删除了字符但是向右多显示一个空格,而且不显示移动光标 那么可以编辑zsh配置文件

vi ~/.zshrc

在.zshrc里添加

TERM=xterm

保存, 然后执行, 使配置生效

source ~/.zshrc

2019-05-01 qnap , qnap-tutorial , qpkg , linux , shell , login-shell , zsh , oh-my-zsh , bash

Cinnamon alt+f2 命令

很早就开始用 Cinnamon 作为 Linux 的主要桌面环境,还折腾过 Cinnamon 的主题,但是其实一直没怎么关注 Alt + F2 的功能,唯一知道的命令就是 r 用来重启 Cinnamon。所以这里就总结总结 Alt+F2 可以用的命令。

内置命令

-‘r’ - restart Cinnamon

  • ‘rt’ - reload the current Cinnamon theme
  • ‘lg’ - start the Looking Glass debugger (which itself seems not to be documented anywhere)

任何 Xwindows 应用

在 Alt + F2 下运行无界面的命令,比如 ls 可能得不到任何结果,但是可以运行比如 firefox 这样有窗口的命令。该命令需要在 PATH 下。

快速打开文件夹

在 Alt + F2 窗口下输入文件目录可以快速使用默认文件浏览器打开该目录。


2019-04-29 cinnamon , commands

drools 编程例子

关于 Drools 更多的介绍 可以参考之前的文章

这篇文章主要讲解如何在项目中执行 DRL 文件并取得结果。

ERROR

如果遇到这样的错误,大部分情况下是 drl 规则文件所在的文件夹,没有被项目识别为 resources 文件夹,在 IntelliJ IDE 中可以使用设置为资源文件夹来解决。

Exception in thread "main" java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
    at org.drools.core.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:212)
    at org.drools.core.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:149)
    at org.drools.compiler.compiler.DrlParser.parse(DrlParser.java:154)
    at org.drools.compiler.compiler.DrlParser.parse(DrlParser.java:144)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.drlToPackageDescr(KnowledgeBuilderImpl.java:541)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addPackageFromDrl(KnowledgeBuilderImpl.java:529)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addKnowledgeResource(KnowledgeBuilderImpl.java:753)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:2296)
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:2285)
    at com.neo.drools.banking.RuleRunner.runRules(RuleRunner.java:32)
    at com.neo.drools.banking.BankingExample1.main(BankingExample1.java:10)
Caused by: java.io.FileNotFoundException: 'Example1.drl' cannot be opened because it does not exist
    at org.drools.core.io.impl.ClassPathResource.getURL(ClassPathResource.java:173)
    at org.drools.core.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:185)
    ... 10 more

2019-04-26 drools , drl , jboss , java , rule-engine

The Silver Searcher: ag 使用

Once I wrote a post about ack-grep, and Franklin Yu left a comment about the silver searcher. He said this tool is much faster than the ack-grep. So this post is about The Silver Searcher. As always, I will introduce what is the Silver Searcher, how to install and use it.

Follow the link, we can see that author claim that this tool started off as a clone of ack, but then diverged slightly. And in most case, this tool is 5-10x faster then ack.

ag 是一个全文检索工具,非常适合查询大量文本文件,或者源代码的场景。

Installation

Find the download link at official site.

apt-get install silversearcher-ag

Usage

ag [file-type] [options] PATTERN [PATH]

As the man describe, recursively search for PATTERN in PATH.

Usage

Most options are similar to grep, like -i, -v, -B, -A etc

查询路径下的内容 Find text under a path

most use case will be find a keyword from a bunch of files. 最常用的一个方式便是在目录中搜索关键词,ag 能够非常快速的搜索文件内容,所以非常适合查询日志,或者代码等文本文件。

ag keyword /path/to/

Count the matches of keywords

ag -c keyword /path/

自定义查询深度

Default depth is 25, if you want unlimited, you should use -1

ag --depth NUM keyword .

查找包含关键字的文件名

If you forget the filename, but only remeber only few letters, you can use -g to print only filenames.

-g 选项表示查询文件名,而不会去查询文件内容。比如说想要查询目录下文件名中包含 Pattern 的文件名,那么可以使用:

ag -g PATTERN .

results will be only filenames. 这样结果就只会打印出符合的文件名。

打印出包含关键字的文件名

上面 -g 选项只会去查询文件名,那么如果想要查找内容中包含某个关键字的文件名,可以使用 -l 选项:

ag -l 'pattern' /path/to

使用 -L 会显示没有匹配的文件名

在特定的文件中查询

ag 提供了 -G 选项,可以用来缩小查询的范围,-G PATTERN 可以指定 Pattern,那么 ag 只会在 -G 指定的文件中查询,比如只查询 .+\.java.java 结尾的文件。

ag -G ".+\.java" "string to search" /path/to

For more details, you can check man ag

Drawback

用了一段时间,唯一发现的缺点就是想要搜索中文内容时,发现ag并不能很好的处理。

reference


2019-04-25 ack-grep , search , grep , ag

Maven 多仓库和镜像配置

之前看 Maven 书的时候对于 Maven 本地配置没有好好研究。这下闲下来从 GitHub 上拉了一个项目来,发现使用单一的 mirror 仓库无法找到一些 jboss 的依赖,所以想起来研究一下 Maven 多仓库和镜像相关的配置。

都知道在 $HOME/.m2/settings.xml 中配置了 Maven 在本地的全局配置,可能对于某些公司内网,已经配置了公司或者内部私有的镜像。但是如果遇到镜像的中央仓库部分依赖不存在的情况,其实就需要依赖外部的仓库。

使用单一仓库

可能对于大部分的公司来说,强制使用了内网提供的单一仓库,force maven 使用单一仓库,mirror 所有请求到单一仓库。这个时候就要求这个单一仓库需要包含所有需要的 artifacts,或者需要设置代理去请求其他仓库,否则 maven 可能找不到某些构建。要做到单一仓库,设置 mirrorOf*.

maven 2.0.5+ 以上版本支持:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

记住这里的 mirrorOf 中配置的星号 ,表示匹配所有的 artifacts,也就是 everything 使用这里的代理地址。这里的 mirrorOf 如果配置了具体的名字,指的是 repository 的名字,继续往下看。

multiple repository config

设置多仓库有两种方法,第一种直接在项目层级 POM 中定义:

<project>
...
  <repositories>
    <repository>
      <id>my-repo1</id>
      <name>your custom repo</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </repository>
    <repository>
      <id>my-repo2</id>
      <name>your custom repo</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </repository>
  </repositories>
...
</project>

这里的 id 就是 mirrorOf 要使用的 ID。

第二种方法是在 ~/.m2/settings.xml 文件中全局修改。

<settings>
 ...
 <profiles>
   ...
   <profile>
     <id>myprofile</id>
     <repositories>
       <repository>
         <id>my-repo2</id>
         <name>your custom repo</name>
         <url>https://maven.aliyun.com/repository/public</url>
       </repository>
       ...
     </repositories>
   </profile>
   ...
 </profiles>

 <activeProfiles>
   <activeProfile>myprofile</activeProfile>
 </activeProfiles>
 ...
</settings>

别忘了激活 profile,或者也可以使用 mvn 参数来指定:

mvn -Pmyprofile ...

这里提供一下 jboss 官方的配置

<profiles>
    <profile>
      <id>jboss</id>
      <repositories>
        <repository>
          <id>jboss-public-repository-group</id>
          <name>JBoss Public Maven Repository Group</name>
          <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>jboss-public-repository-group</id>
          <name>JBoss Public Maven Repository Group</name>
          <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
</profiles>

官方文档

设置镜像

设置镜像的作用是为了加快依赖包的下载速度,理论上来说如果一个仓库 B 可以提供仓库 A 所有的内容,那么可以认为 B 是 A 的一个镜像,比如说 阿里提供了很多仓库的镜像 使用这些镜像可以提高下载速度。

<mirror>
      <!-- 唯一标识一个 mirror -->
      <id>mirror</id>
	  <!-- 代表一个镜像的替代位置,例如 central 就表示代替官方的中央库 -->
      <mirrorOf>external:*,!repo</mirrorOf>
      <name>nexus repository</name>
      <url>https://maven.aliyun.com/repository/public</url>
</mirror>

配置说明:

  • id: 镜像的唯一标识
  • mirrorOf: 指定镜像规则,什么情况下从镜像仓库拉取,官方文档
    • *: 匹配所有,所有内容都从镜像拉取
    • external:*: 除了本地缓存的所有从镜像仓库拉取
    • repo,repo1: repo 或者 repo1 ,这里的 repo 指的仓库 ID
    • *,!repo1: 除了 repo1 的所有仓库
  • name: 名称描述
  • url: 地址

使用场景

Maven 设置中的 mirrorrepository 概念比较容易混淆,一般来说 repository 用来配置远程仓库的地址,mirror 则是作为中央仓库的镜像配置。

所以,当我的需求是,比如在内部远程仓库无法找到依赖时,从外部仓库中下载。那么我要做的就是配置多个 repository,那么当 maven 寻找依赖时就会按照配置的 repository 从上往下依次尝试下载。

<settings>
	<mirrors>
	</mirrors>
	<profiles>
		<profile>
			<id>aliyun</id>
			<repositories>
				<repository>
					<id>aliyun</id>
					<url>https://maven.aliyun.com/repository/public</url>
					<releases><enabled>true</enabled></releases>
					<snapshots><enabled>true</enabled></snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>aliyun</id>
					<url>https://maven.aliyun.com/repository/public</url>
					<releases><enabled>true</enabled></releases>
					<snapshots><enabled>true</enabled></snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
		<profile>
			<id>nexus-163</id>
			<repositories>
				<repository>
					<id>nexus-163</id>
					<name>Nexus 163</name>
					<url>http://mirrors.163.com/maven/repository/maven-public/</url>
					<layout>default</layout>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
					<releases>
						<enabled>true</enabled>
					</releases>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>nexus-163</id>
					<name>Nexus 163</name>
					<url>http://mirrors.163.com/maven/repository/maven-public/</url>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
					<releases>
						<enabled>true</enabled>
					</releases>
				</pluginRepository>
			</pluginRepositories>
		</profile>
		<profile>
		  <id>jboss</id>
		  <repositories>
			<repository>
			  <id>jboss-public-repository-group</id>
			  <name>JBoss Public Maven Repository Group</name>
			  <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
			  <layout>default</layout>
			  <releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			  </snapshots>
			</repository>
		  </repositories>
		  <pluginRepositories>
			<pluginRepository>
			  <id>jboss-public-repository-group</id>
			  <name>JBoss Public Maven Repository Group</name>
			  <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
			  <layout>default</layout>
			  <releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			  </snapshots>
			</pluginRepository>
		  </pluginRepositories>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>aliyun</activeProfile>
		<activeProfile>jboss</activeProfile>
	</activeProfiles>

	<servers>
		<server>
			<id>archiva.internal</id>
			<username>username</username>
			<password></password>
		</server>
		<server>
			<id>archiva.snapshots</id>
			<username>username</username>
			<password></password>
		</server>
	</servers>
</settings>

mirror 与 repository 不同的是,假如配置同一个 repository 多个 mirror 时,相互之间是备份关系,只有当仓库连不上时才会切换到另一个,而如果能连上但是找不到依赖时是不会尝试下一个 mirror 地址的。

reference


2019-04-23 maven , repository , build-tools , java

电子书

本站提供服务

最近文章

  • AI Shell 让 AI 在命令行下提供 Shell 命令 AI Shell 是一款在命令行下的 AI 自动补全工具,当你想要实现一个功能,敲一大段命令又记不住的时候,使用自然语言让 AI 给你生成一个可执行的命令,然后确认之后执行。
  • 最棒的 Navidrome 音乐客户端 Sonixd(Feishin) Sonixd 是一款跨平台的音乐播放器,可以使用 [[Subsonic API]],兼容 Jellyfin,[[Navidrome]],Airsonic,Airsonic-Advanced,Gonic,Astiga 等等服务端。 Sonixd 是一款跨平台的音乐播放器,可以使用 [[Subsonic API]],兼容 Jellyfin,[[Navidrome]],Airsonic,Airsonic-Advanced,Gonic,Astiga 等等服务端。
  • 中心化加密货币交易所 Gate 注册以及认证 Gate.io 是一个中心化的加密货币交易所。Gate 中文通常被称为「芝麻开门」,Gate 创立于 2013 年,前身是比特儿,是一家致力于安全、稳定的数字货币交易所,支持超过 1600 种数字货币的交易,提供超过 2700 个交易对。
  • 不重启的情况下重新加载 rTorrent 配置文件 因为我在 Screen 下使用 rTorrent,最近经常调试修改 rtorrent.rc 配置文件,所以想要找一个方法可以在不重启 rTorrent 的情况重新加载配置文件,网上调查了一下之后发现原来挺简单的。
  • Go 语言编写的网络穿透工具 chisel chisel 是一个在 HTTP 协议上的 TCP/UDP 隧道,使用 Go 语言编写,10.9 K 星星。