关于maven:聊聊maven指定version区间的妙用

前言在咱们开发微服务项目的过程中,难免会依赖各种jar,开发环境可能援用1.0.0-SNAPSHOT,而到了正式环境,则须要援用1.0.0。之前咱们的做法是通过pom配置profile来达到不同环境,应用不同的版本。形如下 <profiles> <!-- 开发环境 --> <profile> <properties> <user-api.version>1.0.0-SNAPSHOT</user-api.version> </properties> <activation> <!-- 指定默认环境 --> <activeByDefault>true</activeByDefault> </activation> </profile> <!-- 生产环境 --> <profile> <id>prod</id> <properties> <properties> <user-api.version>1.0.0</user-api.version> </properties> </profile> </profiles>直到某一天,忘了在哪个开源的pom,看到了形如下写法 <dependency> <groupId>com.github.lybgeek</groupId> <artifactId>lybgeek</artifactId> <version>[1.0,2.0]</version> </dependency>一开始还认为是啥jar那么特立独行,版本号居然是[1.0,2.0],前面理解了一下,才晓得的本人的无知,同时也关上新世界大门 注释[1.0,2.0]这个到底是啥?这个代表其实就是一个version区间,示意的意思是,该区间的版本都是可用版本,默认取最新的版本,即2.0。其余的区间配法示例 (,1.0] x <= 1.0[1.0] x = 1.0 跟间接指定1.0没有区别[1.2,1.3] 1.2 <= x <= 1.3[1.0,2.0) 1.0 <= x < 2.0[1.5,) x >= 1.5(,1.0],[1.2,) x <= 1.0 or x >= 1.2(,1.1),(1.1,) x < 1.1 or x > 1.1 即排除1.1的版本注: x为具体应用的版本号。默认状况下,同版本的快照版本会小于非快照版本 ...

February 27, 2024 · 1 min · jiezi

关于maven:聊聊如何解析pom文件

序本文次要钻研一下如何解析pom文件 maven-modelmaven提供了maven-model的类库能够间接解析 <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-model</artifactId> <version>3.9.4</version> </dependency>应用 MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(new ByteArrayInputStream(data)); Properties properties = model.getProperties();应用MavenXpp3Reader能够间接读取pom文件,之后就能够失去ModelModelmaven-model-3.9.4-sources.jar!/org/apache/maven/model/Model.java public class Model extends ModelBase implements Serializable, Cloneable { private String modelVersion; private Parent parent; private String groupId; private String artifactId; private String version; private String packaging = "jar"; private String name; private String description; private String url; private String childProjectUrlInheritAppendPath; private String inceptionYear; private Organization organization; private List<License> licenses; private List<Developer> developers; private List<Contributor> contributors; private List<MailingList> mailingLists; private Prerequisites prerequisites; private Scm scm; private IssueManagement issueManagement; private CiManagement ciManagement; private Build build; private List<Profile> profiles; private String modelEncoding = "UTF-8"; private File pomFile; //......} Model继承了ModelBaseModelBasemaven-model-3.9.4-sources.jar!/org/apache/maven/model/ModelBase.java ...

August 23, 2023 · 1 min · jiezi

关于maven:Maven进阶学习指南-京东云技术团队

前言当咱们在开发我的项目时,有时须要用到内部依赖组件,例如当咱们须要Json序列化的时候须要用到FastJson组件,咱们能够通过下载对应jar包加载到我的项目中。但当一个大的我的项目同时须要依赖各种各样的内部服务,就存在着配置繁琐、依赖抵触等问题,因而能够通过maven来实现对应的依赖治理性能。 一、Settings配置settings.xml用来配置maven我的项目中的各种参数文件,包含本地仓库、近程仓库、私服、认证等信息。 1.1 配置概述1.1.1 全局settings、用户setting、pom的区别全局 settings.xml 是 maven 的全局配置文件,个别位于${maven.home}/conf/settings.xml,即maven文件夹下的conf中。用户 setting是maven的用户配置文件,个别位于${user.home}/.m2/settings.xml,即每位用户都有一份配置文件。pom.xml 文件是我的项目配置文件,个别位于我的项目根目录下或子目录下。配置优先级从高到低:pom.xml > 本地 settings > 全局 settings 如果这些文件同时存在,在利用配置时,会合并它们的内容,如果有反复的配置,优先级高的配置会笼罩优先级低的。 1.1.2 仓库【重要】如前言所述,咱们依赖的内部服务是须要有中央进行存储的,而存储的中央就称之为仓库。其中仓库又分为本地仓库、地方仓库、镜像仓库、私服。 其对应关系为: (1)本地仓库当我的项目在本地编译或运行时,间接加载本地的依赖服务无疑是最快的。默认状况下,不论在Window还是Linux下,每个用户在本人用户目录下都有一个路径名为.m2/repository/的仓库目录。 而原始的本地仓库是为空的,因而maven须要晓得一个网络上的仓库,在本地仓库不存在时返回下载网络上的仓库,也就是近程仓库。 (2)地方仓库当maven未配置时,会默认申请maven的地方仓库,地方仓库蕴含了这个世界上绝大多数风行的开源java构件,以及源码、作者信息、SCM,信息、许可证信息等,每个月这里都会承受全世界java程序员大略1亿次的拜访,它对全世界java开发者的奉献由此可见一斑。 然而因为最常见的例如网络起因等,国外的地方仓库应用起来并不顺利,因而就有了下载地址为国内的地方仓库,也就是镜像仓库。 (3)镜像仓库总结来说,镜像仓库就是将国外的核心仓库复制一份到国内,这样一来下载速度以及访问速度都将很快。 (4)私服一般来说地方仓库或者镜像仓库都能满足咱们的需要,然而当咱们在公司内合作开发代码时,可能因为零碎保密性起因,有一些其余共事开发的内部依赖只心愿可能被本公司的人应用,而如果上传到镜像仓库则保密性就不复存在了。因而私服最次要的性能时存储一些公司外部不心愿被公开的依赖服务。 1.2 settings配置详解settings.xml配置了本地全局maven的相干配置。 以下是一份seetings.xml的文件配置顶级元素。 <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 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository> <interactiveMode> <usePluginRegistry> <offline> <pluginGroups> <servers> <mirrors> <proxies> <profiles> <activeProfiles></settings>1.2.1 localRepository用来标识本地仓库的地位 D:/Maven/Repository1.2.2 interactiveModemaven 是否须要和用户交互以取得输出。默认为true。 true1.2.3 usePluginRegistrymaven 是否须要应用 plugin-registry.xml 文件来治理插件版本。 false1.2.4 offline用来标识是否以离线模式经营maven。 当零碎不能联网时,能够通过次配置来离线运行。 false1.2.5 servers当应用maven私服时,某些私服须要配置认证信息,须要在此处填写相应的配置。之所以不写在pom.xml中是因为个别我的项目在上传至代码仓库时同样会将pom.xml上传,而setting.xml个别位于用户本地,因而绝对比拟平安。 <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 https://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <!--配置服务端的一些设置。一些设置如平安证书不应该和pom.xml一起散发。这种类型的信息应该存在于构建服务器上的settings.xml文件中。 --> <servers> <!--服务器元素蕴含配置服务器时须要的信息 --> <server> <!--这是server的id(留神不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 --> <id>server001</id> <!--鉴权用户名。鉴权用户名和鉴权明码示意服务器认证所须要的登录名和明码。 --> <username>my_login</username> <!--鉴权明码 。鉴权用户名和鉴权明码示意服务器认证所须要的登录名和明码。明码加密性能已被增加到2.1.0 +。详情请拜访明码加密页面 --> <password>my_password</password> <!--鉴权时应用的私钥地位。和前两个元素相似,私钥地位和私钥明码指定了一个私钥的门路(默认是${user.home}/.ssh/id_dsa)以及如果需要的话,一个密语。未来passphrase和password元素可能会被提取到内部,但目前它们必须在settings.xml文件以纯文本的模式申明。 --> <privateKey>${usr.home}/.ssh/id_dsa</privateKey> <!--鉴权时应用的私钥明码。 --> <passphrase>some_passphrase</passphrase> <!--文件被创立时的权限。如果在部署的时候会创立一个仓库文件或者目录,这时候就能够应用权限(permission)。这两个元素非法的值是一个三位数字,其对应了unix文件系统的权限,如664,或者775。 --> <filePermissions>664</filePermissions> <!--目录被创立时的权限。 --> <directoryPermissions>775</directoryPermissions> </server> </servers> ...</settings>1.2.6 mirrors【重要】用来配置相应的镜像仓库。 ...

June 27, 2023 · 4 min · jiezi

关于maven:centos-8安装maven

DataX源码编译装置须要用到maven yum 装置 wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo# 批改centos版本sudo sed -i s/\$releasever/8/g /etc/yum.repos.d/epel-apache-maven.repoyum install mavenmvn -version源码装置 http://mirrors.hust.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip -O /usr/local/src/apache-maven-bin.tar.gzcd /usr/local/src && tar xzvf apache-maven-bin.tar.gz -C /opt官网

April 25, 2023 · 1 min · jiezi

关于maven:Maven私有仓库Nexus3

Maven公有仓库-Nexus3工作中,可能须要封装一些通用的工具类库然而公司代码较为敏感,个别不能凋谢到公共仓库中此时能够应用Nexus3搭建公司外部应用的公有仓库视频版:BiliBiliDemo步骤应用docker创立Nexus3服务创立我的项目并推送仓库 批改我的项目pom.xml文件配置批改Maven软件配置应用"mvn deploy"命令,推送到到仓库创立我的项目并援用上一步的我的项目 批改Maven软件配置重启IDE应用"mvn install"命令,装置依赖1. 应用docker创立nexus3服务应用docker创立nexus3容器 拜访:http://127.0.0.1:8081较吃资源,启动速度较慢,显示无法访问页面就多等一会儿(电脑渣的可能要个三五分钟,比方我的)docker run -d -p 8081:8081 --name nexus sonatype/nexus3获取nexus3明码 点击页面右上角的"Sign in",按弹窗提醒找到默认明码 默认账号:admin默认明码:容器内的 "/nexus-data/admin.password"会提醒重置明码,改个记得住的明码(或者用默认明码),前面配置须要用到如下图,复制"maven-releases"/"maven-snapshots"仓库地址 nexus-public是一个仓库分组,默认蕴含以下仓库 maven-releases:本地release库maven-snapshots:本地snapshots库maven-central:代理地方maven库,能够改成国内代理,如阿里云(https://maven.aliyun.com/repository/public)2. 创立我的项目并推送仓库批改我的项目pom.xml文件配置间接革新Maven我的项目(或者新建一个Maven我的项目) 执行"mvn package"能打包出jar的我的项目就行如下在pom.xml增加nexus3地址信息 与dependencies/build同级 <dependencies>...略</dependencies> <build>...略</build> <distributionManagement> <repository> <id>maven-releases</id> <name>maven-releases</name> <url>${这里填写从nexus页面上复制的maven-releases的url}</url> </repository> <snapshotRepository> <id>maven-snapshots</id> <name>maven-snapshots</name> <url>${这里填写从nexus页面上复制的maven-snapshots的url}</url> </snapshotRepository> </distributionManagement>推送包 执行 "mvn deoloy"此时报错 "...status: 401 Unauthorized",阐明我的项目配置正确批改Maven软件配置关上 ${maven根目录}/conf/settings.xml 减少nexus账号密码id要和在我的项目pom.xml中配置的统一<servers> <server> <id>maven-releases</id> <username>admin</username> <password>${明码}</password> </server> <server> <id>maven-snapshots</id> <username>admin</username> <password>${明码}</password> </server></servers>再次执行"mvn deploy"就不会报错了 刷新nexus页面上能够看到上传的包 我的项目版本不带"-SNAPSHOT"在"maven-releases"目录否则在"maven-releases"目录3. 创立我的项目并援用上一步的我的项目代码批改Maven软件配置关上 ${maven根目录}/conf/settings.xml 启用镜像,如果有其余镜像能够正文掉重启IDE,pom.xml中像线上的库一样增加dependency即可应用<mirror> <id>nexus-public</id> <mirrorOf>*</mirrorOf> <name>公有仓库</name> <url>${这里填写从nexus页面上复制的maven-public的url}</url></mirror>参考资料docker部署Nexusmaven配置nexus私服

April 16, 2023 · 1 min · jiezi

关于maven:maven-pomxml-dependency和dependencymanagment理解

背景对maven的jar包引入的了解 按优先级降级 ●间接依赖(以后我的项目含有depency) 1.以后我的项目的depency版本 2.以后我的项目的depencymanagment 3.以后我的项目继承的depencymanagment ●间接依赖(以后我的项目无depency) 1.以后我的项目的depencymanagment 2.以后我的项目继承的depencymanagment 3.被依赖我的项目的depency版本 4.被依赖我的项目的depencymanagment 5.被依赖我的项目继承的depencymanagment例子 ●springbootparent为父,指定了depencymanagment,kafka版本为2.0.1 ●project为子,分状况探讨,如果指定版本的话,为2.5.0 ●kafka-api为被依赖我的项目,kafka版本为3.4.0project分状况探讨 ●有父,有kafka-api 1.depency指定kafka,指定版本,kafka为间接依赖,版本为2.5.0 2.depency指定kafka,不指定版本,kafka为间接依赖,应用继承的depencymanagment,版本为2.0.1 3.depency不指定kafka,kafka为间接依赖,应用继承的depencymanagment,版本为2.0.1 ●有父,无kafka-api 1.depency指定kafka,指定版本,kafka为间接依赖,版本为2.5.0 2.depency指定kafka,不指定版本,kafka为间接依赖,应用继承的depencymanagment,版本为2.0.1 3.depency不指定kafka,无kafka ●无父,有kafka-api 1.depency指定kafka,指定版本,kafka为间接依赖,版本为2.5.0 2.depency指定kafka,不指定版本,kafka为间接依赖,行为不可预测,可能报错,也可能沿用之前胜利引入过的版本 3.depency不指定kafka,kafka为间接依赖,版本为3.4.0 ●无父,无kafka-api 1.depency指定kafka,指定版本,kafka为间接依赖,版本为2.5.0 2.depency指定kafka,不指定版本,kafka为间接依赖,行为不可预测,可能报错,也可能沿用之前胜利引入过的版本 3.depency不指定kafka,无kafka

April 15, 2023 · 1 min · jiezi

关于maven:阿里云settings

基于 apache maven 3.9.0 批改 <?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless 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 ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder 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.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.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/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. | | 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-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> <mirror> <id>maven-default-http-blocker</id> <mirrorOf>external:http:*</mirrorOf> <name>Pseudo repository to mirror external repositories initially using HTTP.</name> <url>http://0.0.0.0/</url> <blocked>true</blocked> </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 | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish, particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <!-- | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | might hypothetically look like: | | ... | <plugin> | <groupId>org.myco.myplugins</groupId> | <artifactId>myplugin</artifactId> | | <configuration> | <tomcatLocation>${tomcatPath}</tomcatLocation> | </configuration> | </plugin> | ... | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | anything, you could just leave off the <value/> inside the activation-property. | <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> --> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> --></settings>

March 13, 2023 · 7 min · jiezi

关于maven:底层到底做了什么-maven的mvn命令

mvn命令,用于构建java我的项目。这篇文章通过剖析mvn脚本,看看mvn命令底层做了什么。 在开始看mvn命令以前,先查了github,有maven的我的项目,因而maven自身应该是一个java我的项目。另外,还有intellij-community我的项目,能够晓得这也是一个java我的项目。 上面正式开始看mvn脚本。 首先进入maven我的项目的根目录,进入bin目录,能够看到mvn脚本。 cd bin通过vim关上mvn脚本。 vim mvn间接到脚本开端,能够看到是启动一个java命令。 191 exec "$JAVACMD" \192 $MAVEN_OPTS \193 $MAVEN_DEBUG_OPTS \194 -classpath "${CLASSWORLDS_JAR}" \195 "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \196 "-Dmaven.home=${MAVEN_HOME}" \197 "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \198 "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \199 ${CLASSWORLDS_LAUNCHER} "$@"有几个要害的变量,从脚本后面找进去。能够看出 maven应用是plexus-classworlds-*.jar,启动类是org.codehaus.plexus.classworlds.launcher.Launcher 95 JAVACMD="$JAVA_HOME/bin/java"105 CLASSWORLDS_JAR=echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar106 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher到此,mvn命令底层做了什么曾经根本分明。

January 9, 2023 · 1 min · jiezi

关于maven:一招解决以Maven构建的Java项目中jar包依赖错乱问题

日期作者版本备注2022-10-05dingbinthu@163.comV1.0 理论工作中咱们常常遇到以maven构建的java工程中遇到jar包依赖凌乱问题,这时候常常要用到 mvn dependency:tree -Dverbose mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId:version -Dexcludes=groupId:artifactId:version 命令来查看jar错综依赖关系,并排查解决。 举例:对我的一个java工程,我用命令:mvn clean install -U 编译时报错如下: 22-11-19 15:27:19,639 INFO com.mchange.v2.log.MLog(MLog.java:80) ## MLog clients using log4j logging.22-11-19 15:27:19,782 INFO com.mchange.v2.c3p0.C3P0Registry(C3P0Registry.java:204) ## Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]22-11-19 15:27:19,832 WARN com.mchange.v2.c3p0.DriverManagerDataSource(DriverManagerDataSource.java:108) ## Could not load driverClass com.mysql.cj.jdbc.Driverjava.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:315) at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:101) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:133) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)显然这个maven构建提醒找不到com.mysql.cj.jdbc.Driver 这个类(这个类是mysql8.0以及当前版本的 jdbc类),显示是在c3p0-0.9.1.1 这个jar包里调用的。查看我的pom.xml里c3p0相干的依赖配置如下: ...

November 19, 2022 · 4 min · jiezi

关于maven:91pom-相关的配置propertiesbuildrepositories

属性配置: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version> </properties>build插件配置: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> </plugins> </build>配置maven的库: <repositories> <repository> <id>public</id> <name>aliyun nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>aliyun nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories>maven 依赖指向本地: <dependency> <groupId>com.linewell</groupId> <artifactId>typp-frame-core</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/typp-frame-core-0.0.1-SNAPSHOT.jar</systemPath> </dependency>将本地jar包增加到maven仓库 语法: mvn install:install-file -Dfile=jar包的地位(参数一) -DgroupId=groupId(参数二) -DartifactId=artifactId(参数三) -Dversion=version(参数四) -Dpackaging=jar理论例子: mvn install:install-file -Dfile=E:/res/jar_lib/ag777-1.0.jar -DgroupId=ag777 -DartifactId=ag777 -Dversion=1.0 -Dpackaging=jar

October 21, 2022 · 1 min · jiezi

关于maven:74maven-打包jar配置

<plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-web</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>target/META-INF/resources</outputDirectory> <resources> <resource> <directory>src/main/webapp</directory> <includes> <include>**</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-lib</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.1</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.demo.MainApplication</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>16</source> <target>16</target> </configuration> </plugin> </plugins> <!-- SpringBoot我的项目默认举荐应用的前端引擎是thymeleaf 当初咱们要应用SpringBoot集成jsp,手动指定jsp最初编译的门路 同时SpringBoot集成jsp编译jsp的门路是规定好的:META-INF/resources --> <resources> <resource> <!-- 源文件夹 --> <directory>src/main/webapp</directory> <!-- 指定编译到的门路为 META-INF/resources --> <targetPath>META-INF/resources</targetPath> <!-- 指定源文件夹中的哪些资源须要进行编译 --> <includes> <include>**</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**</include> </includes> </resource> </resources>

October 12, 2022 · 1 min · jiezi

关于maven:73wagonssh远程上传jar等文件并部署

属性值: <properties> <ssh.ip>192.168.207.109</ssh.ip> <ssh.username>root</ssh.username> <ssh.pwd>1q2w3e4r5t</ssh.pwd> <ssh.run.skip>false</ssh.run.skip> <ssh.lib.skip>true</ssh.lib.skip> <ssh.yml.skip>true</ssh.yml.skip> <ssh.exec.skip>false</ssh.exec.skip></properties>增加扩大依赖包: <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>2.10</version> </extension> </extensions></build>增加插件plugin: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>2.0.2</version> <configuration> <settings> <servers> <server> <id>wagon-ssh</id> <username>${ssh.username}</username> <password>${ssh.pwd}</password> </server> </servers> </settings> <serverId>wagon-ssh</serverId> <url>scp://${ssh.ip}</url> <skip>false</skip> </configuration> <executions> <execution> <id>ssh-upload-yml</id> <phase>package</phase> <goals> <goal>upload</goal> </goals> <configuration> <skip>${ssh.yml.skip}</skip> <fromDir>target/classes</fromDir> <toDir>${ssh.path}</toDir> <includes>*.yml</includes> </configuration> </execution> <execution> <id>ssh-upload-lib</id> <phase>package</phase> <goals> <goal>upload</goal> </goals> <configuration> <skip>${ssh.lib.skip}</skip> <fromDir>target</fromDir> <toDir>${ssh.path}</toDir> <includes>lib/*</includes> </configuration> </execution> <execution> <id>ssh-upload-run</id> <phase>package</phase> <goals> <goal>upload</goal> </goals> <configuration> <skip>${ssh.run.skip}</skip> <fromDir>target</fromDir> <toDir>${ssh.path}</toDir> <includes>${project.build.finalName}.jar</includes> </configuration> </execution> <execution> <id>ssh-exec</id> <phase>package</phase> <goals> <goal>sshexec</goal> </goals> <configuration> <skip>${ssh.exec.skip}</skip> <displayCommandOutputs>true</displayCommandOutputs> <commands> <command>mv ${ssh.path}/${project.build.finalName}.jar ${ssh.path}/run.jar</command> </commands> </configuration> </execution> </executions> </plugin>

October 12, 2022 · 1 min · jiezi

关于maven:72maven-单独运行其中一个模块

在多模块的状况下,独自打包其中一个模块 mvn clean package -pl com.xx:xx-auth -am -Pdev

October 11, 2022 · 1 min · jiezi

关于maven:MacBook-Linux安装Maven

MacBook Linux装置Maven官网下载地址: https://maven.apache.org/down...官网下载对应的版本 bin.tar.gz包 #解压tar -zxvf xxx.tar.gz #减少环境变量 MacBook我用的是zsh,Linux的配置文件/etc/profilevim ~/.zshrc#最初退出export MVN_HOME=/Users/liang/software/apache-maven-3.2.5export PATH=$MVN_HOME/bin:$PATH#使配置失效 source ~/.zshrc#查看maven版本mvn -version#显示如下Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)Maven home: /Users/liang/software/apache-maven-3.2.5Java version: 1.8.0_171, vendor: Oracle CorporationJava home: /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jreDefault locale: zh_CN, platform encoding: UTF-8OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

September 13, 2022 · 1 min · jiezi

关于maven:整合mavensonarjacoco

配置maven插件在maven的settings中配置插件 <pluginGroups> <pluginGroup>org.sonarsource.scanner.maven</pluginGroup> <pluginGroup>org.jacoco</pluginGroup> </pluginGroups> <profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <sonar.host.url> ${sonar.url} </sonar.host.url> <sonar.login>${user.token}</sonar.login> </properties> </profile> </profiles>打包参数 mvn clean jacoco:prepare-agent test jacoco:report sonar:sonar -Dsonar.projectKey=${projectName} -Dsonar.java.binaries=target install -e -am常见谬误You're not authorized to run analysis. Please contact the project administrator Sonarqube local 应用了sonar.login参数,传了token,但在执行mvn命令时呈现了该谬误. 解决办法:办法1. 敞开sonarqube的权限, 配置>配置>权限>Force user authentication(不举荐),这样能够删除sonar.login参数, sonar会主动创立我的项目;办法2. 应用-Dsonar.projectKey=${projectName}, 指定project名称就不会报错了Your project contains .java files, please provide compiled classes with sonar.java.binaries property应用新版本的sonarqube呈现解决办法: 办法1. 回退sonarqube java插件的版本(不举荐) 办法2. 应用-Dsonar.java.binaries=targetjacoco没有生成测试报告,Skipping Jacoco execution due to missing execution data file 这个谬误很恶心,始终产生surefire的测试报告, 没有jacoco的测试报告.因为我是用命令行执行的jacoco,没有用pom.xml配置,要与Azure整合,尝试了半天。解决办法:须要残缺的增加一下参数,test必须放两头, 放其它地位,jacoco也不肯定失效 ...

August 26, 2022 · 1 min · jiezi

关于maven:Maven介绍环境配置与IDEA项目创建

1. Maven简介Maven是专门用于治理和构建Java我的项目的工具,官网:http://maven.apache.org/ 。它的次要性能有: 1.1 标准化的我的项目构造每一个开发工具(IDE)都有本人不同的我的项目构造,它们相互之间不通用。比方我再eclipse中创立的目录,无奈在idea中进行应用,这就造成了很大的不不便。 Maven提供了一套标准化的我的项目构造,所有的IDE应用Maven构建的我的项目齐全一样,所以IDE创立的Maven我的项目能够通用。 1.2 标准化的构建流程(编译,测试,打包,公布……) 如上图所示咱们开发了一套零碎,代码须要进行编译、测试、打包、公布,这些操作如果须要重复进行就显得特地麻烦,而Maven提供了一套简略的命令来实现我的项目构建。 1.3 不便的依赖管理机制依赖治理其实就是治理你我的项目所依赖的第三方资源(jar包、插件)。比方你须要JDBC和Druid的话,就要去网上下载对应的依赖包,复制到我的项目中,还要将jar包退出工作环境这一系列的操作。如下图所示 而Maven应用规范的 ==坐标== 配置来治理各种依赖,只须要简略的配置就能够实现依赖治理。 如上图左边所示就是mysql驱动包的坐标,在我的项目中只须要写这段配置,其余都不须要咱们放心,Maven都帮咱们进行操作了。是不是简略了不少?? 2. 仓库咱们创立Maven我的项目,在我的项目中应用坐标来指定我的项目的依赖,那么依赖的jar包到底存储在什么中央呢?其实依赖jar包是存储在咱们的本地仓库中。而我的项目运行时从本地仓库中拿须要的依赖jar包。 仓库分类: 本地仓库:本人本地计算机上的一个目录地方仓库:由Maven团队保护的寰球惟一的仓库。基本上你能想到的jar包,这里都有 地址: https://repo1.maven.org/maven2/近程仓库(私服):个别由公司团队搭建的公有仓库当我的项目中应用坐标引入对应依赖jar包后,首先会查找本地仓库中是否有对应的jar包: 如果有,则在我的项目间接援用;如果没有,则去地方仓库中下载对应的jar包到本地仓库。 当然如果搭建有近程仓库,则jar包的查找程序则变为: 3. Maven装置配置3.1 下载安装包官网下载:https://maven.apache.org/down...链接:https://pan.baidu.com/s/1vzSe... 提取码:0tiw解压 apache-maven-3.6.1.rar 既装置实现 倡议解压缩到没有中文、特殊字符的门路下。记住你的目录。解压缩后的目录构造如下: bin目录 : 寄存的是可执行命令。mvn 命令重点关注。conf目录 :寄存Maven的配置文件。settings.xml 配置文件前期须要批改。lib目录 :寄存Maven依赖的jar包。Maven也是应用java开发的,所以它也依赖其余的jar包。3.2 配置环境变量 此电脑 右键 --> 高级零碎设置 --> 高级 --> 环境变量 在零碎变量处新建一个变量 MAVEN_HOME 在 Path 中进行配置 关上cmd进行验证,呈现如图所示示意装置胜利: 3.3 配置本地仓库批改 conf/settings.xml 中的 <localRepository> 为一个指定目录作为本地仓库,用来存储jar包。我的是: 当然如果你不配置的话,会有一个默认本地仓库目录: 3.4 配置阿里云私服地方仓库在国外,所以下载jar包速度可能比较慢,而阿里公司提供了一个近程仓库,外面根本也都有开源我的项目的jar包。 批改 conf/settings.xml 中的 <mirrors>标签,为其增加如下子标签: ...

August 15, 2022 · 1 min · jiezi

关于maven:Maven的BOM应用

BOM 概念BOM(Bill of Materials)是由 Maven 提供的性能,它用来定义一套互相兼容的 jar 包版本汇合,应用时只须要依赖该 BOM 文件,即可应用须要的依赖 jar 包,且无需再指定版本号。BOM 的保护方负责版本升级,并保障 BOM 中定义的 jar 包版本之间的兼容性。 BOM 创立BOM (Bill of Materials Dependency)实质上是一个 pom 文件,当咱们在构建 Springboot 我的项目的时候引入的 spring-boot-dependencies 依赖,其本质就是一个 pom 文件,如下: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.6.8</version> <type>pom</type> <scope>import</scope></dependency>spring-boot-dependencies 的 pom 文件外面定义了一套互相兼容的可能满足 Springboot 利用所需的依赖包版本汇合,这些依赖包定义在 dependencyManagement 中。另外,还定义了一些构建利用可能用到的插件,这些插件定义在 pluginManagement 中。 咱们也能够定义本人的 BOM,比方定义一个 pom 文件,其中 packaging 指定为 pom,在 dependencyManagement 中定义所需的依赖包版本汇合,如下: <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.phoenix</groupId> <artifactId>phoenix-framework</artifactId> <version>1.0-SNAPSHOT</version> <name>phoenix-framework</name> <packaging>pom</packaging> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring-boot.mybatis>2.2.2</spring-boot.mybatis> <fastjson.version>1.2.83</fastjson.version> <guava.version>30.0-jre</guava.version> <mybatis.version>3.5.10</mybatis.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${spring-boot.mybatis}</version> </dependency> </dependencies> </dependencyManagement></project>BOM 应用BOM 在理论利用中的次要作用就是将 jar 包的版本集中管理,在须要用到依赖 jar 包的利用中导入 BOM,而后配置所需的依赖 dependency 即可,无需指定 jar 包的版本号。如下: ...

July 23, 2022 · 1 min · jiezi

关于maven:Maven自动更新SNAPSHOT包

在开发和测试阶段,开发人员常常将开发的jar以SNAPSHOT快照版本形式deploy到私服,提供给其余的我的项目应用。Maven默认以天为单位查看更新,对于咱们继续集成的频率来说,这显然是不够的。 如果要实时强制查看SNAPSHOT更新,能够以下形式: 用命令进行maven打包的时候,加上-U参数: mvn clean install -U -Dmaven.test.skip=true批改IDEA配置,勾选“Always update snapshots”批改Maven配置配置setting.xml中的profile为实时更新快照版本<profiles> <profile> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>libs-release</name> <url>http://xxx.com:80/repository/maven-public</url> </repository> <repository> <!-- 实时查看并且更新快照版本的插件 --> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </snapshots> <id>snapshots</id> <name>libs-snapshot</name> <url>http://xxx.com:80/repository/maven-snapshot</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>plugins-release</name> <url>http://xxx.com:80/repository/maven-public</url> </pluginRepository> <pluginRepository> <!-- 实时查看并且更新快照版本的插件 --> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </snapshots> <id>snapshots</id> <name>plugins-snapshot</name> <url>http://xxx.com:80/repository/maven-public</url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile></profiles>

June 29, 2022 · 1 min · jiezi

关于maven:maven正确的集成命令U-B-等

在继续集成服务器上应用怎么的 mvn 命令集成我的项目,这个问题乍一看答案很显然,不就是 mvn clean install 么?事实上比拟好的集成命令会略微简单些,上面是一些总结: 不要忘了clean: clean可能保障上一次构建的输入不会影响到本次构建。应用deploy而不是install: 构建的SNAPSHOT输入该当被主动部署到公有Maven仓库供别人应用,这一点在后面曾经具体阐述。应用-U参数: 该参数能强制让Maven查看所有SNAPSHOT依赖更新,确保集成基于最新的状态,如果没有该参数,Maven默认以天为单位查看更新,而继续集成的频率应该比这高很多。应用-e参数:如果构建出现异常,该参数能让Maven打印残缺的stack trace,以不便剖析谬误起因。应用-Dmaven.repo.local参数:如果继续集成服务器有很多工作,每个工作都会应用本地仓库,下载依赖至本地仓库,为了防止这种多线程应用本地仓库可能会引起的抵触,能够应用-Dmaven.repo.local=/home/juven/ci/foo-repo/这样的参数为每个任务分配本地仓库。应用-B参数:该参数示意让Maven应用批处理模式构建我的项目,可能防止一些须要人工参加交互而造成的挂起状态。综上,继续集成服务器上的集成命令应该为 mvn clean deploy -B -e -U -Dmaven.repo.local=xxx 。此外,定期清理继续集成服务器的本地Maven仓库也是个很好的习惯,这样能够避免浪费磁盘资源,简直所有的继续集成服务器软件都反对本地的脚本工作,你能够写一行简略的shell或bat脚本,而后配置以天为单位主动清理仓库。须要留神的是,这么做的前提是你有公有Maven仓库,否则每次都从Internet下载所有依赖会是一场噩梦。

June 29, 2022 · 1 min · jiezi

关于maven:Maven中scopeprovided和optionaltrue的区别

先说成果,maven依赖申明中加了 <scope>provided</scope>,或者加了 <optional>true</optional>,从成果上看是一样的,都会中断依赖传递,察看下图:图中,我的项目B别离依赖了C和D,只不过一个申明了optional=true,一个申明了scope=provided,而后我的项目A再申明了B的依赖,此时在我的项目A环境中,既没有C,也没有D,所以在成果上看,它们是一样的。 那它们有哪些区别呢? 先看一下maven官网文档上对二者的形容: optional: If project Y depends on project Z, the owner of project Y can mark project Z as an optional dependency, using the "optional" element. When project X depends on project Y, X will depend only on Y and not on Y's optional dependency Z. The owner of project X may then explicitly add a dependency on Z, at her option. (It may be helpful to think of optional dependencies as "excluded by default.")provided ...

June 23, 2022 · 1 min · jiezi

关于maven:Maven的scope详解

前言我的项目中 jar 包的加载个别有这么几个阶段:编译、测试、运行,理论我的项目构建过程中 jar 包应该可能满足不同的阶段有选择性地加载应用的需要,Maven 通过 scope 配置来满足这个需要。 分类compile(默认)在编译、测试和运行时都要应用该依赖 jar 包。 provided编译和测试无效,运行有效。如 servlet-api,在我的项目运行时,tomcat 等容器曾经提供,无需Maven 反复引入。 runtime测试和运行无效,编译有效。如 jdbc 驱动实现,编译时只需接口,测试或运行时才须要具体的 jdbc 驱动实现。 test只对测试无效,表明只在测试的时候须要,在编译和运行时将无奈应用该类依赖 jar 包,如 junit。 system被依赖 jar 不会从 maven 仓库中查找,而是从本地零碎中获取,须要和 systemPath 元素一起应用,用于指定本地零碎中 jar 文件的门路。 import只在 <dependencyManagement> 中应用,示意从其它的 pom 中导入 dependency 的配置,这样能够简化配置导入的复杂度,同时实现 jar 包版本的对立治理等。上面常常遇到的应用 import 的一个实例: <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.3.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency></dependencies>

June 19, 2022 · 1 min · jiezi

关于maven:Maven的仓库分类

本地仓库Maven 的本地仓库,在装置 Maven 后并不会创立,它是在第一次执行 maven 命令的时候才被创立。本地仓库地位通过localRepository设置:<localRepository>C:/apache-maven-3.2.5/repository</localRepository> 近程仓库近程仓库包含:地方仓库、私服。 地方仓库Maven 地方仓库是由 Maven 社区提供的仓库,其中蕴含了大量罕用的库,无需显示的配置。在\lib\maven-model-builder-3.2.5.jar\org\apache\maven\model\pom-4.0.0.xml文件中,能够看到地方仓库的配置。 <repositories> <repository> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> <releases> <updatePolicy>never</updatePolicy> </releases> </pluginRepository> </pluginRepositories>私服私服是一种非凡的近程仓库,个别用来治理公司外部的 jar 包,公司外部本人开发的公共类库,提供通用的性能,或者提供给其余我的项目依赖应用,这些 jar 包上传到私服,其余我的项目中通过配置依赖能够下载到这些专用的 jar 包。setting 文件中私服的配置: <profiles> <profile> <id>nexus-repo</id> <repositories> <repository> <id>nexus-public</id> <url>http://localhost:8080/nexus/content/groups/public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus-repo</activeProfile> </activeProfiles>通过 profile 配置私服信息,最初激活 profile 配置就能够失常从私服下载jar包了。 ...

June 18, 2022 · 1 min · jiezi

关于maven:maven项目jar包deploy到私服

maven我的项目pom文件配置<distributionManagement> <repository> <id>releases</id> <name>Local Release Repository</name> <url>http://localhost:8080/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Local Snapshot Repository</name> <url>http://localhost:8080/nexus/content/repositories/snapshots/</url> </snapshotRepository></distributionManagement>maven的settings文件配置<server> <id>releases</id> <username>admin</username> <password>admin123</password></server><server> <id>snapshots</id> <username>admin</username> <password>admin123</password></server>留神setting文件server中的id和我的项目pom文件中的id统一,同时指定精确的username和password,在deploy的时候,maven会通过username和password认证,认证通过,就会将本地maven我的项目生成的jar包上传到私服上。

June 18, 2022 · 1 min · jiezi

关于maven:推荐一款代码依赖包安全漏洞检查插件

前言明天向大家举荐一款代码依赖包破绽查看maven插件--dependency-check-maven。通过这个插件能够扫描出我的项目中是否依赖曾经存在的安全漏洞包 如何应用前置条件:该插件须要应用maven 3.1或更高版本 1、在我的项目pom引入dependency-check-maven插件 GAV <build> <plugins> <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>7.0.0</version> <configuration> <autoUpdate>true</autoUpdate> </configuration> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build>2、切换到我的项目的target目录,执行mvn dependency-check:check注: 如果是idea,能够间接如下,右键运行 第一次执行的话,他的速度会挺慢的,因为他须要从NIST托管的国家破绽数据库下载破绽数据到本地备份库。 在执行的过程中,可能会呈现 Failed to initialize the RetireJS repo解决的方法 下载jsrepository.json并将该文件放到maven私仓地址\org\owasp\dependency-check-data\7.0目录下 执行结束后,会在target目录下产生dependency-check-report.html文件 3、通过浏览器关上dependency-check-report.html点击相应的链接信息,能够查看相应的破绽形容 总结本文简略的介绍一下如何利用dependency-check-maven插件来查看代码依赖包安全漏洞。相干具体用法,能够查看如下链接https://jeremylong.github.io/DependencyCheck/dependency-check-maven/index.html demo链接https://github.com/lyb-geek/springboot-learning/tree/master/springboot-git-commit

May 10, 2022 · 1 min · jiezi

关于maven:Maven进阶

1.简介 2.Maven根底概念 3.Maven我的项目

April 18, 2022 · 1 min · jiezi

关于maven:Maven

March 29, 2022 · 0 min · jiezi

关于maven:图文并茂做开发这么久了还不会搭建服务器Maven私有仓库这也太Low了吧

大家好,我是冰河~~ 最近不少小伙伴想在本人公司的内网搭建一套Maven私服环境,可本人搭建的过程中,或多过少的总会呈现一些问题,问我可不可以出一篇如何搭建Maven私服的文章。这不,就有了这篇文章嘛。 好了,其余的不多说了,接下来,咱们就一起来搭建Maven私服环境吧! 环境阐明环境:CentOS 6.x~8.0、 JDK8、 Sonatype Nexus、 MavenIP:192.168.50.131root 用户操作装置Nexus前提:已装置 JDK8 并配置好了环境变量,小伙伴们自行搭建JDK8环境,这里我就不再赘述了。置信小伙伴们都可能正确搭建JDK8环境。 下载Nexus下载Nexus(这里,我应用的是:nexus-2.11.2-03-bundle.tar.gz) ,下载地址:http://www.sonatype.org/nexus... ,咱们也能够在服务器的命令行输出如下命令下载nexus-2.11.2-03-bundle.tar.gz安装文件。 # wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz也能够到链接:https://download.csdn.net/dow... 下载 解压Nexus# mkdir nexus# tar -zxvf nexus-2.11.2-03-bundle.tar.gz -C nexus# cd nexus# lsnexus-2.11.2-03 sonatype-work(一个 nexus 服务,一个公有库目录)编辑 Nexus编辑 Nexus 的 nexus.properties 文件,配置端口和 work 目录信息(保留默认) # cd nexus-2.11.2-03# lsbin conf lib LICENSE.txt logs nexus NOTICE.txt tmp查看目录构造, jetty 运行 # cd conf# vi nexus.properties# Jetty sectionapplication-port=8081application-host=0.0.0.0nexus-webapp=${bundleBasedir}/nexusnexus-webapp-context-path=/nexus# Nexus sectionnexus-work=${bundleBasedir}/../sonatype-work/nexusruntime=${bundleBasedir}/nexus/WEB-INF编辑 nexus 脚本,配置 RUN_AS_USER 参数# vi /usr/local/nexus/nexus-2.11.2-03/bin/nexus#RUN_AS_USER=改为: RUN_AS_USER=root防火墙中关上 8081 端口# vi /etc/sysconfig/iptables增加: ...

March 15, 2022 · 2 min · jiezi

关于maven:Maven常见操作命令

背景最近在基于Maven构建自动化公布流水线,发现当我的项目多、我的项目之间依赖多时,理解Maven的命令应用,真是锦上添花。特为大家整顿了一套Maven常见命令及应用小技巧。倡议珍藏,甚至打印进去放在办公桌以备疾速应用。 废话不多说,间接上干货。 Maven常见命令应用我的项目目录构造: --P(父工程pom) -- A (子工程 - common) -- B (子工程 - biz 依赖common) -- C (子工程 - Web 依赖B、间接依赖A)创立类命令创立一般Maven我的项目mvn archetype:create -DgroupId=packageName -DartifactId=projectName创立之后,能够用IDE进行我的项目导入。 创立Web Maven我的项目mvn archetype:create -DgroupId=packageName -DartifactId=webappName -DarchetypeArtifactId=maven-archetype-webapp创立之后,能够用IDE进行我的项目导入。 公布第三方Jar到本地库中mvn install:install-file -DgroupId=xxx.xx.xxxx -DartifactId=xxx -Dversion=0.0.1 -Dpackaging=jar -Dfile=门路/xxx-0.0.1.jar构建打包类命令编译源代码mvn compile编译测试代码mvn test-compile编译测试代码mvn test打包我的项目mvn package革除打包的我的项目mvn cleanpackage、install、deploy等命令常于该命令配合应用。 革除历史打包并从新打包mvn clean package最罕用的命令之一。 革除并install到本地mvn clean install查看以后我的项目已被解析的依赖mvn dependency:list罕用于Jar包依赖抵触排查等。 上传到私服mvn deploy简单组合命令强制查看更新后打包mvn clean package -U-U参数,强制查看更新,避免缓存等起因应用历史依赖,在自动化公布脚本中会常常用到。 打包排除单元测试mvn clean package -Dmaven.test.skip=true打包并指定环境mvn clean package -P testtest为maven中配置的不同打包环境名称。 打包指定子项目和父我的项目mvn clean install -pl C -am -Dmaven.test.skip=true阐明:对父工程P、子模块C、以及子模块C依赖的B、A模块执行mvn clean install操作,波及到的P、A、B、C模块全副install到本地。 ...

February 7, 2022 · 1 min · jiezi

关于maven:Idea操作Maven-高级篇

Idea操作Maven 高级篇:通过下面学习大抵曾经理解了: Maven根底篇什么是Maven——为啥要用——根底的构建:Maven 能够说是Java开发必不可少的工具了:ok!, 接下来深刻理解 Maven的高级篇!分模块构建工程[利用]Maven 继承[依赖] 和聚合何为聚合?我的项目开发通常是分组分模块开发每个模块开发实现一个独自的性能。如果: 要运行整个工程须要将每个模块聚合在 一起运行;比方: dao、service、web 三个工程最终会打一个独立的 war 运行.聚合: 能够在 dao service web 模块之上在建设一个 父模块: 通过父模块来聚合工程, 运行只须要编译 打包父工程即可! 何为继承?和Java 很相似: 子类 继承extends 父类,便具备了父类的个性;Maven继承:是为了打消反复,如果将 dao、service、web 离开创立独立的工程则每个工程的;pom.xml 会有很多雷同的依赖Jar包~ 能够将这些反复的配置,提取进去在父工程的 pom.xml 中定义对立治理申明公共 Jar。父模块的打包形式必须为pom,否则无奈构建我的项目。 子模块中通过配置来表明其继承与哪一个父模块:通常继承和聚合同时应用。 Maven聚合 Demo案例:数据库: 父工程 bbs-parent 创立一个一般的Maven工程删掉 src 父工程是不写代码的, 只是做了一个聚合治理的性能...增加所须要的Maven模块:dao 数据层entity 实体层service 业务逻辑层web 展现层,以上都是一般的Maven工程即可,而这里须要指定为 web Maven模板的工程...(可参考上一篇文~)父工程 pom.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- 组 名 版本 --> <groupId>org.example</groupId> <artifactId>bbs-parent</artifactId> <version>1.0-SNAPSHOT</version> <!-- 父工程的打包形式! --> <!-- 咱们见过打包形式为jar和war的,然而聚合模块的打包形式必须为pom,否则无奈实现构建。 --> <packaging>pom</packaging> <!-- 父工程集成的子工程! --> <modules> <module>bbs-dao</module> <module>bbs-service</module> <module>bbs-entity</module> <module>bbs-web</module> <!--<module>..聚合的子工程..</module>--> </modules> <!-- 通用配置.. --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <spring.version>4.2.4.RELEASE</spring.version> </properties> <!-- SSM工程所须要的Jar,申明在父工程中,子工程也能够应用.... --> <dependencies> <!-- spring-命名空间:apl --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <!-- spring-beans: Bean的Apl --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.7.4</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.7.4</version> </dependency> <!-- 日志依赖 --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-nop</artifactId> <version>1.6.1</version> </dependency> <!-- JSON依赖 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.31</version> </dependency> </dependencies></project>留神:<spring.version>4.2.4.RELEASE</spring.version> Spring版本 4.0以上是JDK 1.8应用的!!3.几 的版本是JDK1.7的!!哭死,这个谬误找半天!!bbs-entity 模块实体层:定义我的项目所须要的pojo... ...

January 19, 2022 · 4 min · jiezi

关于maven:Idea操作Maven详细使用

Idea操作Maven具体应用:Maven简介什么是 MavenMaven 的正确发音是[mevn] "卖v",而不是“马瘟”以及其余什么瘟。Maven 是一个项目管理工具,它蕴含了一个我的项目对象模型 (POM:Project Object Model),一组规范汇合。Maven 能解决什么问题现在咱们构建一个我的项目须要用到很多第三方的类库 Jar包如写一个应用Spring的Web我的项目就须要引入大量的jar包, 而往往一个Jar包往往又会援用其余Jar包,短少其中任何一个Jar包都会导致我的项目编译失败。每开发一个我的项目都会须要大量的Jar包 , 一个一般的Java我的项目兴许理论源码只有几MB甚至KB,但加上Jar之后兴许就几十MB。而同样的我的项目,如果咱们应用 Maven 工程来构建,那么总体上工程的大小会小很多。部署至服务器中... **Maven就是一款帮忙程序员构建我的项目的工具,咱们只须要通知Maven须要哪些Jar 包,它会帮忙咱们 下载/提供 所有的Jar,极大晋升开发效率。** Maven 的两个经典作用:依赖治理 ~也就是治理jar包(波及仓库常识,上面会讲)~Maven 的一个外围个性就是依赖治理。当咱们波及到多模块的我的项目(蕴含成百个模块或者子项目),治理依赖就变成一项艰难的工作。Maven 展现出了它对解决这种情景的高度管制。 传统的 WEB 我的项目中,咱们必须将工程所依赖的 jar 包复制到工程中,导致了工程的变得很大。那么maven 工程是如何使得工程变得很少呢?Idea常见一般Maven我的项目目录:maven工程中不间接将 jar包导入到工程中,而是通过在 pom.xml 文件中增加所需jar包的坐标。这样就很好的防止了 jar 间接引入进来, 使工程变大~ 在须要用到 jar 包的时候,再通过pom.xml文件中的坐标到一个专门用于”寄存 jar 包的仓库”(maven 仓库)中依据坐标从而找到这些 jar 包拿去运行。而且过程并不需要放心 到仓库中找到 jar 包这样会影响程序性能:maven 中也有索引的概念,通过建设索引,能够大大提高加载 jar 包的速度,使得咱们认为 jar 包根本跟放在本地的工程文件中再读取进去的速度是一样的。”寄存 jar 包的仓库”长什么样? 仓库,顾名思义,也就是寄存一些我的项目必备的食粮(jar包)的中央。Maven中仓库分为三类:本地仓库:寄存在本地服务器中,当运行我的项目的时候,maven会主动依据配置文件查找本地仓库,再从本地仓库中调用jar包应用。近程仓库(私服):当本地仓库中没有我的项目所须要的jar包时,那么maven会持续查找近程仓库,个别近程仓库指的是公司搭建的公有服务器,也叫私服;当jar包在私服中查找到之后,maven会将jar包下载到本地仓库中,下次应用的时候就不必再去找近程仓库。地方仓库:当近程仓库获取不到jar包时,就须要到地方仓库去查找,并下载在近程仓库中,本地仓库再从近程仓库中下载回来应用。**此由maven团队保护,据说截止至16年,曾经有2亿个包在仓库中!能够这么说,咱们须要的包所有起源都是地方仓库,并不需要放心没有jar包。**一键构建我的项目从编译、测试、运行、打包、装置、 部署整个过程都交给 maven进行治理,这个过程称为构建。 一键构建: 指的是整个构建过程, 应用 maven几个命令能够轻松实现整个工作。Maven 规范化构建流程如下:这个目前晓得就好, 上面联合我的项目实例具体解说~感触; IDEA应用Maven工程:我的idea是中文的, 而且版本1.3的有差别的同学多多了解~留神!应用Maven工程最好要在有网的状况下, 对于一些组件 Jar都是要联网下载的... 首先idea配置maven的装置目录和本地仓库Idea每次创立一个新的Maven时候, 倡议看看, 不然本地资源库错了Jar乱放到处下载...并不好~文件——设值——输入框输出Maven ...

January 14, 2022 · 3 min · jiezi

关于maven:别再自建仓库了云效Maven仓库不限容量免费用

别再自建仓库了,云效Maven仓库不限容量收费用,云效制品仓库 Packages提供maven公有仓库、npm公有仓库、通用制品仓库等企业级私有制品仓库,用于maven、npm等软件包和依赖治理。不限容量、收费用 立刻体验 制品仓库 Packages (新版)云效制品仓库 Packages (https://packages.aliyun.com/) 是阿里云出品的一款企业级公有仓库服务,提供基于 Maven、Gradle、NPM 等软件包管理工具的企业级公有仓库服务,用于治理企业级依赖托管。仓库反对治理 Maven 制品和 NPM 制品,并反对配置近程仓库,一键迁徙现有私库。提供租户隔离、权限管制、高可用存储等服务,全面保障企业制品平安。立刻体验 Maven 公有仓库(老版)在云效中如果须要上传、下载公有的二方库,能够应用云效的企业级Maven公有仓库服务。 点击‘我的’链接,抉择左侧菜单栏中的‘设置’按钮,将‘公有仓库’服务退出到左侧菜单栏中。 这样在左侧菜单栏会看到‘公有仓库’链接。 开明仓库 尽管启用了公有仓库服务,但云效并没有真正的为您创立企业级Maven公有仓库。点击左侧菜单栏'公有仓库'链接后,如果您是企业管理员,会呈现以下界面: '点击开明'即可开明仓库服务。 企业的普通用户并没有开明仓库的权限,则须要分割您的企业管理员进行开明操作。 开明胜利当前显示界面如下: 仓库地址 云效会主动为该企业生成两个Maven私库,一个是Release仓库,用于存储正式版本的二方库;另一个是Snapshot仓库,用于寄存Snapshot版本的二方库。 settings.xml配置 公有仓库不容许匿名上传和下载二方库,云效为每个公有仓库生成了相应的用户名和明码。请留神不要泄露该用户名和明码。 用户能够通过该页面下载残缺的settings.xml文件,也能够依据本人的需要在settings.xml文件中增加公共仓库的镜像地址。 上传二方库用户能够通过UI上传二方库。目前反对通过GAV的模式进行上传,单个二方库的大小限度为300M。 检索 对二方库的检索反对关键字搜寻和GAV搜寻两种模式。 用户能够查看检索进去的二方库的根本信息,也能够下载二方库。 在云效构建中应用公有仓库服务 默认状况下如果用户开明了Maven公有仓库服务,那么通过云效构建时,云效会主动尝试从该企业的公有仓库中拉取须要的二方库,用户无需进行额定的配置。而如果用户本人在代码库根目录中定制了settings.xml文件,那么就须要用户自行把公有仓库的配置信息增加到该文件中。具体能够通过后面的介绍来理解公有仓库的settings.xml配置。用户能够查看在云效构建中应用Maven公有仓库服务理解更多内容。 别再自建仓库了,云效Maven仓库不限容量收费用,云效制品仓库 Packages提供maven公有仓库、npm公有仓库、通用制品仓库等企业级私有制品仓库,用于maven、npm等软件包和依赖治理。不限容量、收费用 立刻体验 如果感觉对您有所帮忙别忘记点赞、珍藏和关注,理解更多详情微信公众号搜寻【云效】随时理解云效动静

January 7, 2022 · 1 min · jiezi

关于maven:window下maven的安装和配置阿里镜像源

参考阿里巴巴开源镜像站 在window下maven的装置和配置阿里镜像源 首先下载解压maven压缩包 下载地址: https://maven.aliyun.com/ 解压后进入装置目录的conf/settings.xml 批改为阿里的镜像源保留 <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url></mirror> 配置环境变量 实现 cmd里输出mvn -version查看版本

December 24, 2021 · 1 min · jiezi

关于maven:Ubuntu20安装maven并切换阿里镜像源

参考阿里巴巴开源镜像站 装置maven并切换阿里镜像源 执行sudo apt install maven 装置maven mvn -v 查看版本 批改为国内阿里镜像源,找到/usr/share/maven/conf/settings.xml文件 关上并批改以下 <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url></mirror> 可能会显示只读 能够批改下权限在保留 sudo chmod 777 /usr/share/maven/conf/settings.xml 而后保留

December 24, 2021 · 1 min · jiezi

关于maven:一款好用的Maven插件-Maven-Helper

作者:烧鸡太子爷 起源:恒生LIGHT云社区 Maven Helper是什么先看下插件官网的介绍吧: 本插件可用来不便显示maven的依赖树,在没有此插件时,如果想看maven的依赖树须要输出命令行: mvn dependency:tree 才可查看依赖。如果想看是否有依赖包抵触的话也须要输出命令行等等的操作;而如果装置Maven Helper插件就可免去命令行困扰,通过界面即可操作实现。 怎么装置我本人应用的是IDEA 2019.3.1的版本,所以后续所有的都以该版本为例 1、关上IDEA 插件配置界面 File -> Settings ->Plugins,在搜寻框中输出Maven Helper就能够搜寻到,点击install 2、重启IDEA 重启后关上一个pom.xml文件,如果呈现Dependency Analyzer则表明装置胜利了 应用Conflicts(查看抵触)点击[Dependency Analyzer]选项->[Conflicts]会列出以后我的项目所有有抵触的依赖。 右击抵触插件要排除的版本,抉择Exclude就能够将不要的版本排除。 pom文件将主动生成exclusions代码,应用起来还是十分不便的。 All Dependencies as List(列表模式查看所有依赖)点击[Dependency Analyzer]选项->[All Dependencies as List]会以列表模式查看所有依赖。 All Dependencies as Tree(树模式查看所有依赖)点击[Dependency Analyzer]选项->[All Dependencies as Tree]会以树模式查看所有依赖。 查找指定库的依赖在搜寻框搜寻关键字,就能够查找到指定库的依赖 参考https://plugins.jetbrains.com...

December 8, 2021 · 1 min · jiezi

关于maven:第三方开源库license扫描工具简述

开源软件的代码开源在github这类公开的代码仓库,这给人一种错觉,让咱们认为能够随便的应用开源软件,其实开源软件有license协定,敌对的协定比方Apache 协定,能够在商业软件中应用,不开源,而像GPL协定,一旦应用就必须开源。 商业软件产品不可避免会应用大量的开源组件,但大部分状况不开源,所以在上线前有必要查看组件的license,比方是否依赖GPL。最终上线前可能应用内部商业软件进行扫描,比方Black Duck和Fossa,然而在小守业公司或者让商业银行扫描前,能够采纳开源软件进行预扫描,上面简略介绍调研的开源license扫描软件状况。 "Linux基金会企业开源指南"提供了开源我的项目相干的组件,从中找到license相干的开源工具,包含LicenseFinder、scancode-toolkit、fossology。测试中发现,scancode-toolkit、fossology是对本我的项目内代码的license进行格局查看,不满足咱们的须要。LicenseFinder在测试过程中有”执行mvn失败“的问题,因而也无奈应用。Linux基金会举荐的开源我的项目在这次需要前全军覆没了。 采纳maven的plugin,license-maven-plugin,后果很香。应用办法,这篇文章里写的很分明 ”利用 maven 自动化检测 License“。其实,LicenseFinder底层源码也依赖了license-maven-plugin。 应用gradle构建的我的项目,能够思考License Gradle Plugin, 另外还有google公布的plugin,oss-licenses-plugin plugin根本的原理都是,下载并扫描依赖库的pom文件或者META_INF文件夹里的LICENSE.md。极少数依赖我的项目里没有版本阐明,这部分在license-maven-plugin的后果里有特地阐明,这时能够手动到maven仓库里查看。在测试中发现这样的包其实在maven仓库里也没有license,因为依赖库信息就是从maven仓库下载的。 集体认为license-maven-plugin的扫描办法以及数据源是牢靠的,扫描后果能作为license依赖状况的反对数据。

November 29, 2021 · 1 min · jiezi

关于maven:入门maven本文足矣

以前开发的时候,如果A我的项目须要某个jar包,可能去网上搜寻下载jar包,而后复制粘贴在开发对应的地位,如果B我的项目也须要这个jar包,那么同样须要再次手动复制粘贴到对应的地位。 为了解决这个问题,包治理应运而生,其中最通用以maven和gradle为主,前者次要侧重于java我的项目,后者侧重于android我的项目。留神,说的是侧重于,而不是就是。 什么是maven呢,让咱们来看下官网定义 At first glance Maven can appear to be many things, but in a nutshell Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing: BuildsDocumentationReportingDependenciesSCMsReleasesDistributionIf you want more background information on Maven you can check out The Philosophy of Maven and The History of Maven. Now let's move on to how you, the user, can benefit from using Maven. ...

October 24, 2021 · 2 min · jiezi

关于maven:jar包升级之解决方案-jacksonmapperasl

我的项目背景: 应要求我的项目进行jar包降级,扫描到的jackson-mapper-asl-1.9.6.jar 具备高危破绽CVE-2018-14718 ==>    cve详情 形容: 2.9.7 之前的 FasterXML jackson-databind 2.x 可能容许近程攻击者通过利用失败来阻止 slf4j-ext 类进行多态反序列化来执行任意代码。 以后我的项目应用的依赖是jackson-mapper-asl-1.9.6.jar 查阅mvnrepository官网依赖 可知 其最新的更新版本是1.9.13 而上文提到的是 jackson-databaind 两者artifactId 都对应不上,揣测jackson-mapper-asl 迁徙到了 jackson-databaind. 关上jackson-mapper-asl的mvn官网地址 发现的确曾经迁徙到了jackson-databind 此时咱们只须要剔除jackson-mapper-asl的依赖,并退出迁徙后的指定版本的依赖即可: <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.13.0</version></dependency>而用idea去在我的项目中查问时却并未发现jackson-mapper-asl,那他是怎么引进来的呢,持续摸索发现: 我的项目中引入了jackson-jaxrs,而他依赖于jackson-mapper-asl; 于是点开jackson-jaxrs mvn地址 发现它也前移到了 jackson-jaxrs-json-provider 查看最新版本援用的jackson-databind版本 发现是想要的 间接在我的项目中引入即可 <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>2.13.0</version> </dependency>最初启动我的项目发现报错: 21:29:36.854 - WARN [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:551] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionManage': Cannot create inner bean 'org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider#6f74669c' of type [org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider] while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider#6f74669c': Failed to introspect bean class [org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/JsonMappingException21:29:36.866 - ERROR [org.springframework.boot.SpringApplication:771] - Application startup failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionManage': Cannot create inner bean 'org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider#6f74669c' of type [org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider] while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider#6f74669c': Failed to introspect bean class [org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/JsonMappingException at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)点开对应的配置文件,是配置的javaBean找不到了 ...

October 15, 2021 · 1 min · jiezi

关于maven:appassemblermavenplugin详解

始终很好奇开源软件的启动脚本是怎么写进去的,直到最近看到seata pox.xml 才理解到有个appassembler-maven-plugi插件非常简单。能够用过简略xml配置,就能够将我的项目打包并且生成多个平台的启动脚本,非常简单、实用,上面我全方位带大家去了如何去应用它。 介绍插件依据官网介绍,这个插件次要用于生成启动 java 应用程序的脚本,能将我的项目依赖jar可能打包目录中,并且它们退出启动脚本类门路中。反对平台 Unix-variantsWindows NT (Windows 9x is NOT supported)Java Service Wrapper (JSW) 能够很不便得在各个平台(windows,linux,max os)治理Java过程,治理JVM,启动进行,开机启动,治理内存溢出的异样 标准版还能够发谬误日志email,检测死锁。官网阐明次要命令:appassembler:assemble 打包我的项目并且配置bin 启动脚本,能够了解为应用相似spring-boot-maven-plugin打包进去我的项目,能够通过java -jar 形式启动我的项目,然而不反对stop、satus、restart这些操作,比拟原始。appassembler:create-repository 创立一个 appassembler 存储库,就是将工程打成jarappassembler:generate-daemons 生成基于 JSW 的守护过程包装器,大多数人都是应用这个,重点讲。 appassembler:assemble <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>appassembler-maven-plugin</artifactId> <version>2.1.0</version> <configuration> <platforms> <platform>unix</platform> <platform>windows</platform> </platforms> <!--包的寄存路劲--> <assembleDirectory>${project.build.directory}/${project.name}</assembleDirectory> <repositoryName>lib</repositoryName> <!--启动脚本目录--> <binFolder>bin</binFolder> <!--配置文件门路--> <configurationDirectory>conf</configurationDirectory> <!--是否copy配置文件--> <copyConfigurationDirectory>true</copyConfigurationDirectory> <!--从哪里copy配置文件--> <configurationSourceDirectory>src/main/resources</configurationSourceDirectory> <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath> <!--flag 示意间接将jar放到lib 外面--> <repositoryLayout>flat</repositoryLayout> <encoding>UTF-8</encoding> <logsDirectory>logs</logsDirectory> <tempDirectory>tmp</tempDirectory> <programs> <program> <mainClass>tk.shenyifeng.demo.DemoApplication</mainClass> <id>demo</id> <jvmSettings> <extraArguments> <extraArgument>-server</extraArgument> <extraArgument>-Xms256M</extraArgument> <extraArgument>-Xmx256M</extraArgument> <extraArgument>-Xss512k</extraArgument> <extraArgument>-Xloggc:@BASEDIR@/logs/demo_gc.log</extraArgument> <extraArgument>-verbose:gc</extraArgument> <extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument> <extraArgument>-XX:HeapDumpPath=@BASEDIR@/logs/java_heapdump.hprof</extraArgument> </extraArguments> </jvmSettings> </program> </programs> </configuration> </plugin>运行命令 mvn package appassembler:assemble 就能够在target/工程名/下看见打包好的工程,进入bin 目录能够看见有unix、windows 两大平台的运行脚本,然而这个脚本只有启动工程,不反对stop、restart 。 ...

October 11, 2021 · 1 min · jiezi

关于maven:Maven-Jar包冲突看看高手是怎么解决的

接手了一套比拟有年代感的零碎,打算把重构及遇到的问题写成系列文章,老树发新枝,重温一些实战技术,分享给大家。【重构02篇】:Maven我的项目Jar包管理机制、抵触解决。 常识背景Jar包抵触在软件开发过程中是不可避免的,因而,如何疾速定位抵触源,了解抵触导致的过程及底层原理,是每个程序员的必修课。也是晋升工作效率、应答面试、在团队中怀才不遇的机会。 实际中可能直观感触到的Jar包抵触体现往往有这几种: 程序抛出java.lang.ClassNotFoundException异样;程序抛出java.lang.NoSuchMethodError异样;程序抛出java.lang.NoClassDefFoundError异样;程序抛出java.lang.LinkageError异样等;这是可能直观出现的,当然还有隐性的异样,比方程序执行后果与预期不符等。上面,咱们就剖析一下Maven我的项目中Jar包的解决机制及引起抵触的起因。 Maven Jar包管理机制在Maven我的项目中,想要理解Jar抵触必须得先理解一下Maven是如何治理的Jar包的。这波及到Maven的一些个性,比方依赖传递、最短门路优先准则、最先申明准则等。 依赖传递准则当在Maven我的项目中引入A的依赖,A的依赖通常又会引入B的jar包,B可能还会引入C的jar包。这样,当你在pom.xml文件中增加了A的依赖,Maven会主动的帮你把所有相干的依赖都增加进来。 比方,在Spring Boot项中,当引入了spring-boot-starter-web: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>此时Maven的依赖构造可能是这样的: 下面这种关系,咱们就能够了解为依赖的传递性。即当一个依赖须要另外一个依赖撑持时,Maven会帮咱们把相应的依赖顺次增加到我的项目当中。 这样的益处是,应用起来就十分不便,不必本人挨个去找依赖Jar包了。害处是会引起Jar包抵触,咱们前面会讲到。 最短门路优先准则依赖链路一:次要依据依赖的门路长短来决定引入哪个依赖(两个抵触的依赖)。 举例说明: 依赖链路一:A -> X -> Y -> Z(21.0)依赖链路二:B -> Q -> Z(20.0)我的项目中同时引入了A和B两个依赖,它们间接都引入了Z依赖,但因为B的依赖链路比拟短,因而最终失效的是Z(20.0)版本。这就是最短门路优先准则。 此时如果Z的21.0版本和20.0版本区别较大,那么就会产生Jar包抵触的体现。 最先申明优先准则如果两个依赖的门路一样,最短门路优先准则是无奈进行判断的,此时须要应用最先申明优先准则,也就是说,谁的申明在前则优先选择。 举例说明: 依赖链路一:A -> X -> Z(21.0)依赖链路二:B -> Q -> Z(20.0)A和B最终都依赖Z,此时A的申明(pom中引入的程序)优先于B,则针对抵触的Z会优先引入Z(21.0)。 如果Z(21.0)向下兼容Z(20.0),则不会呈现Jar包抵触问题。但如果将B申明放后面,则有可能会产生Jar包抵触。 Jar包抵触产生的起因下面讲了Maven保护Jar包的三个准则,其实每个准则会产生什么样的Jar包抵触,曾经大略理解了。这里再来一个综合示例。 举例说明: 依赖链路一:A -> B -> C -> G21(guava 21.0)依赖链路二:D -> F -> G20(guava 20.0)假如我的项目中同时引入了A和D的依赖,依照依赖传递机制和默认依赖调节机制(第一:门路最近者优先;第二:第一申明优先),默认会引入G20版本的Jar包,而G21的Jar包不会被援用。 如果C中的办法应用了G21版本中的某个新办法(或类),因为Maven的解决,导致G21并未被引入。此时,程序在调用对应类时便会抛出ClassNotFoundException异样,调用对应办法时便会抛出NoSuchMethodError异样。 排查定位Jar包抵触在高版本的IDEA中曾经自带了Maven依赖治理插件,顺次执行:关上pom.xml文件,在文件内右击,抉择Maven,抉择Show Dependencies即可查看Maven的依赖层级构造: 执行之后展现的成果便是最开始的spring-boot-web那样成果,在图中能够分明的看到都应用了哪些依赖,它们的层级,是否有抵触的jar包等。抵触局部会用红色标出,同时标出Maven默认抉择了哪个版本。 如果你的IDEA版本中默认没有Maven治理插件,也可装置Maven Helper,通过这块插件来帮你剖析Jar包抵触。 装置完插件,重启之后,关上pom.xml文件,在文件上面的Dependency Analyzer视图中便能够看到Jar包抵触的后果剖析: 此时,对于哪些Jar包抵触了,便高深莫测。同时,能够右击抵触的Jar包,执行”Exclude“进行排除,在pom.xml中便会主动增加排除jar包的属性。 对于本地环境能够利用Maven Helper等插件来解决,但在预生产或生成环境中就没那么不便了。此时能够通过mvn命令来定位突出的细节。 ...

October 6, 2021 · 1 min · jiezi

关于maven:深入探讨Maven中的物料清单BOM

深入探讨:Maven中的物料清单 2019年6月4日 阿尤什·普拉沙(Ayush Prashar)Java,项目管理资料清单,依赖治理,Maven,Maven插件 浏览工夫: 3 分钟 最近,在应用Spring WebFlux时,我遇到了一个十分有用的物料清单概念,也称为BOM表( bill of materials),这个概念实际上并不仅限于Spring。BOM 是 Spring 帮忙咱们遗记与传递依赖项无关的问题,把注意力放到关注我的项目需要的几种办法之一。 因而,当咱们通常创立一个具备数十个或数百个依赖项的大型项目时,很大可能应用传递性依赖项是在我的项目外部应用的通用项。因而,假如咱们有一个称为 “common-3.0.0.RELEASE” 的依赖项,它由日志记录的工件应用,而测试框架应用的 “common-2.9.0.Release”这个版本。在这种状况下就会有抵触。咱们须要确保取得可用的版本,以便两个工件能够协同工作。 Maven 有一种为咱们解决这个问题的办法。它应用依赖关系调解(dependency mediation)的概念。它用一个被称为依赖项的门路的概念。领有最短我的项目门路的包将被其余包选中。假如在咱们的例子中,依赖链相似于 log4j -> commons-2.9.0.Release 和 JUnit -> unit-tests -> common.3.0.0., Maven 抉择commons 2.9,因为它的依赖门路间隔以后 POM 更短。 然而,当咱们能够搞对时,为什么要依附某种内部办法呢?通过在 POM 中指定它,咱们始终能够应用咱们心愿的甚至能够过渡的版本。当然,但这会使咱们的 POM 凌乱,因为咱们要写入的可能会很多。 咱们能够让依赖治理(dependency management )来管制,兴许是一个更好的方法。 物料清单Maven 让咱们在独自的 pom 中定义依赖项或传递性依赖项的版本。在此 pom 中,咱们申明了依赖项的版本和范畴。因而,咱们能够集中探讨所有依赖项细节。 让咱们创立一个示例物料清单 pom 文件。 能够看出,物料清单是一个齐全失常的 POM 文件,咱们能够在其中蕴含依赖项信息。 如何应用它?当初咱们理解到,BOM是一个文件,其中蕴含无关咱们我的项目的任何依赖项版本的所有信息。下一步是将此文件蕴含在咱们的原始POM中。 一种做到这一点的形式就是Spring的形式,就像父我的项目一样继承它。咱们须要做的就是在父标记中提供父信息。 只管这是 Spring 的工作形式,但咱们不能从多个父pom继承。因而,如果您心愿从多个继承,咱们会在依赖项中传递凭据。 优先级因而,有多种确定版本的办法,这意味着有一个优先程序。 在POM中间接申明中提供的版本具备最高优先级。父pom中提供的版本具备第二优先权。导入的pom版本排名第三最初,咱们从依赖关系调解中失去的版本如果在继承多个 pom 时发生冲突,则按程序更早申明的依赖项优先。 因而,当初您能够理解为什么在Spring pom中能够进行神奇的主动配置,BOM是什么, 以及在须要进行指定版本的状况下该怎么做。 ...

September 23, 2021 · 1 min · jiezi

关于maven:别再自建仓库了云效Maven仓库不限容量免费用

别再自建仓库了,云效Maven仓库不限容量收费用,云效制品仓库 Packages提供maven公有仓库、npm公有仓库、通用制品仓库等企业级私有制品仓库,用于maven、npm等软件包和依赖治理。不限容量、收费用不限容量、收费应用云效DevOps 制品仓库 Packages (新版)云效制品仓库 Packages (https://packages.aliyun.com/) 是阿里云出品的一款企业级公有仓库服务,提供基于 Maven、Gradle、NPM 等软件包管理工具的企业级公有仓库服务,用于治理企业级依赖托管。仓库反对治理 Maven 制品和 NPM 制品,并反对配置近程仓库,一键迁徙现有私库。提供租户隔离、权限管制、高可用存储等服务,全面保障企业制品平安。立刻体验 Maven 公有仓库(老版)在云效中如果须要上传、下载公有的二方库,能够应用云效的企业级Maven公有仓库服务。 点击‘我的’链接,抉择左侧菜单栏中的‘设置’按钮,将‘公有仓库’服务退出到左侧菜单栏中。 这样在左侧菜单栏会看到‘公有仓库’链接。 开明仓库 尽管启用了公有仓库服务,但云效并没有真正的为您创立企业级Maven公有仓库。点击左侧菜单栏'公有仓库'链接后,如果您是企业管理员,会呈现以下界面: '点击开明'即可开明仓库服务。 企业的普通用户并没有开明仓库的权限,则须要分割您的企业管理员进行开明操作。 开明胜利当前显示界面如下: 仓库地址 云效会主动为该企业生成两个Maven私库,一个是Release仓库,用于存储正式版本的二方库;另一个是Snapshot仓库,用于寄存Snapshot版本的二方库。 settings.xml配置 公有仓库不容许匿名上传和下载二方库,云效为每个公有仓库生成了相应的用户名和明码。请留神不要泄露该用户名和明码。 用户能够通过该页面下载残缺的settings.xml文件,也能够依据本人的需要在settings.xml文件中增加公共仓库的镜像地址。 上传二方库用户能够通过UI上传二方库。目前反对通过GAV的模式进行上传,单个二方库的大小限度为300M。 检索 对二方库的检索反对关键字搜寻和GAV搜寻两种模式。 用户能够查看检索进去的二方库的根本信息,也能够下载二方库。 在云效构建中应用公有仓库服务 默认状况下如果用户开明了Maven公有仓库服务,那么通过云效构建时,云效会主动尝试从该企业的公有仓库中拉取须要的二方库,用户无需进行额定的配置。而如果用户本人在代码库根目录中定制了settings.xml文件,那么就须要用户自行把公有仓库的配置信息增加到该文件中。具体能够通过后面的介绍来理解公有仓库的settings.xml配置。用户能够查看在云效构建中应用Maven公有仓库服务理解更多内容。 别再自建仓库了,云效Maven仓库不限容量收费用,云效制品仓库 Packages提供maven公有仓库、npm公有仓库、通用制品仓库等企业级私有制品仓库,用于maven、npm等软件包和依赖治理。不限容量、收费用 不限容量、收费应用云效DevOps

September 15, 2021 · 1 min · jiezi

关于maven:云效Maven私有仓库不限容量免费用

云效制品仓库 Packages提供maven公有仓库、npm公有仓库、通用制品仓库等企业级私有制品仓库,用于maven、npm等软件包和依赖治理。不限容量、收费用不限容量、收费应用云效DevOps 制品治理仓库 云效 Packages 为您主动创立了两个 Maven 仓库,一个 release 库和一个 snapshot 库。 图1.Maven 仓库列表 进入仓库后,能够通过仓库指南实现 仓库凭证设置、制品文件的上传和下载、公有库迁徙。 图2.Maven 仓库指南 点击查看凭证,可查看您仓库的集体凭证。 包治理 包列表下展现仓库下所有二进制包文件,反对通过 Group Id 和 Artifacts Id 进行包文件搜寻。 图3.Maven 包列表 点击包文件展现包文件信息,默认展现最新版本信息,点击可切换版本。 图4.Maven 包详情 仓库设置 根本信息根本信息可设置仓库的公开性、仓库形容。 图1.根本信息 仓库公开性、成员角色、权限之间的关系可查看:仓库成员权限一节 代理设置 反对设置仓库代理,这样云效私库既具备上传下载包的能力,又具备代理其余仓库的能力。当应用云效私库下载包时,它也会尝试从近程仓库拉取包,并且缓存在云效私库。 你能够间接代理阿里云的公共代理库,也可设置代理您的公有仓库。 图2.代理设置 仓库成员权限 仓库成员 可将云效企业内的成员增加为仓库成员,可将仓库成员设置为管理员和成员角色。 图1.成员设置 角色权限 默认企业拥有者为仓库拥有者,其余企业成员须要在仓库中设置成员和角色。仓库公开性、成员角色之间的关系如下: 本地下载指南 本地下载制品文件失败排查 拜访https://packages.aliyun.com/,制品搜寻中搜寻依赖包,如果不存在,请上传到公有仓库中;如果曾经存在,操作下一步。从https://packages.aliyun.com/下载settings.xml,本地应用这份下载到的settings文件。默认的这份settings中的配置是snapshot的依赖从snapshot的仓中下载,release版本的依赖从release仓中下载,如果依赖传错了仓库,请批改默认的settings文件配置或者从新上传依赖。或者本地工具配置中应用的User settings file为云效私服中下载的原setting文件。在本机新建一个空的目录,比方/tmp/repo,而后在代码根目录下运行mvn clean install -s settings.xml -U -DskipTests -Dmaven.repo.local=/tmp/repo,查看构建是否胜利。留神: -s 参数后为下载的settings.xml的文件门路。如果本地执行这个命令还不行,则参考4为了确保本地settings.xml配置正确,请在本地运行 mvn help:effective-settings ,通过日志查看私库地址是否曾经配置进去本地maven版本最好应用3.5.5及以上若以上信息均无误,请操作下载代码,查看具体报错信息,且将该信息提供进去。将已有私库同步云效 本文档帮忙您将已有 Maven 私库中的制品包批量迁徙到云效的 Maven 私库中。 ...

September 15, 2021 · 1 min · jiezi

关于maven:第二十篇Maven-IntelliJ之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven IntelliJIntelliJ IDEA 曾经内建了对 Maven 的反对。咱们在此例中应用的是 IntelliJ IDEA 社区版 11.1。 IntelliJ IDEA 的一些个性列出如下: 能够通过 IntelliJ IDEA 来运行 Maven 指标。能够在 IntelliJ IDEA 本人的终端里查看 Maven 命令的输入后果。能够在 IDE 里更新 Maven 的依赖关系。能够在 IntelliJ IDEA 中启动 Maven 的构建。IntelliJ IDEA 基于 Maven 的 pom.xml 来实现自动化治理依赖关系。IntelliJ IDEA 能够通过本人的工作区解决 Maven 的依赖问题,而无需装置到本地的 Maven 仓库,尽管须要依赖的我的项目在同一个工作区。IntelliJ IDEA 能够主动从近程 Maven 仓库上下载须要的依赖和源码。IntelliJ IDEA 提供了创立 Maven 我的项目,pom.xml 文件的向导。在 IntelliJ IDEA 里创立一个新的我的项目应用新建我的项目向导来导入一个 Maven 我的项目。 关上 IntelliJ IDEA。抉择 File Menu > New Project 选项。抉择 import project from existing model 选项。 ...

September 8, 2021 · 1 min · jiezi

关于maven:第十九篇-Maven-NetBeans之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven NetBeansNetBeans 6.7 及更新的版本曾经内置了 Maven。对于以前的版本,可在插件管理中心获取 Maven 插件。此例中咱们应用的是 NetBeans 6.9。 对于 NetBeans 的一些个性如下: 能够通过 NetBeans 来运行 Maven 指标。能够应用 NetBeans 本身的控制台查看 Maven 命令的输入。能够更新 Maven 与 IDE 的依赖。能够在 NetBeans 中启动 Maven 的构建。NetBeans 基于 Maven 的 pom.xml 来实现自动化治理依赖关系。NetBeans 能够通过本人的工作区解决 Maven 的依赖问题,而无需装置到本地的 Maven 仓库,尽管须要依赖的我的项目在同一个工作区。NetBeans 能够主动从近程 Moven 库上下载须要的依赖和源码。NetBeans 提供了创立 Maven 我的项目,pom.xml 文件的向导。NetBeans 提供了 对于Maven 仓库的浏览器,使您能够查看本地存储库和注册在内部的 Maven 仓库。在 NetBeans 里关上一个 Maven 我的项目关上 NetBeans抉择 File Menu > Open Project 选项抉择我的项目的门路,即应用 Maven 创立一个我的项目时的存储门路。假如咱们创立了一个我的项目: consumerBanking. 通过 Maven 构建 Java 我的项目 查看如何应用 Maven 创立一个我的项目。 ...

September 8, 2021 · 2 min · jiezi

关于maven:第十八篇-Maven-Eclipse之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven EclipseEclipse 提供了一个很好的插件 m2eclipse ,该插件能将 Maven 和 Eclipse 集成在一起。 在最新的 Eclipse 中自带了 Maven,咱们关上,Windows->Preferences,如果会呈现上面的画面: 上面列出 m2eclipse 的一些特点: 能够在 Eclipse 环境上运行 Maven 的指标文件。能够应用其自带的控制台在 Eclipse 中间接查看 Maven 命令的输入。能够在 IDE 下更新 Maven 的依赖关系。能够应用 Eclipse 发展 Maven 我的项目的构建。Eclipse 基于 Maven 的 pom.xml 来实现自动化治理依赖关系。它解决了 Maven 与 Eclipse 的工作空间之间的依赖,而不须要装置到本地 Maven 的存储库(须要依赖我的项目在同一个工作区)。它能够主动地从远端的 Maven 库中下载所须要的依赖以及源码。它提供了向导,为建设新 Maven 我的项目,pom.xml 以及在已有的我的项目上开启 Maven 反对。它提供了远端的 Maven 存储库的依赖的疾速搜寻。在 Eclipse 中导入一个 Maven 的我的项目关上 Eclipse抉择 File > Import > option抉择 Maven Projects 选项。点击 Next 按钮。 抉择我的项目的门路,即应用 Maven 创立一个我的项目时的存储门路。假如咱们创立了一个我的项目: consumerBanking. 通过 Maven 构建 Java 我的项目 查看如何应用 Maven 创立一个我的项目。点击 Finish 按钮。 ...

September 8, 2021 · 2 min · jiezi

关于maven:第十七篇-Maven-Web-应用之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven Web 利用本章节咱们将学习如何应用版本控制系统 Maven 来治理一个基于 web 的我的项目,如何创立、构建、部署曾经运行一个 web 利用。 创立 Web 利用咱们能够应用 maven-archetype-webapp 插件来创立一个简略的 Java web 利用。 关上命令控制台,进入到 C:\MVN 文件夹,而后执行以下的 mvn 命令: C:\MVN>mvn archetype:generate -DgroupId=com.companyname.automobile -DartifactId=trucks -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false执行完后 Maven 将开始解决,并且创立残缺的于Java Web 我的项目的目录构造。 [INFO] Scanning for projects...[INFO] Searching repository for plugin with prefix: 'archetype'.[INFO] -------------------------------------------------------------------[INFO] Building Maven Default Project[INFO] task-segment: [archetype:generate] (aggregator-style)[INFO] -------------------------------------------------------------------[INFO] Preparing archetype:generate[INFO] No goals needed for project - skipping[INFO] [archetype:generate {execution: default-cli}][INFO] Generating project in Batch mode[INFO] --------------------------------------------------------------------[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0[INFO] --------------------------------------------------------------------[INFO] Parameter: groupId, Value: com.companyname.automobile[INFO] Parameter: packageName, Value: com.companyname.automobile[INFO] Parameter: package, Value: com.companyname.automobile[INFO] Parameter: artifactId, Value: trucks[INFO] Parameter: basedir, Value: C:\MVN[INFO] Parameter: version, Value: 1.0-SNAPSHOT[INFO] project created from Old (1.x) Archetype in dir: C:\MVN\trucks[INFO] -------------------------------------------------------------------[INFO] BUILD SUCCESSFUL[INFO] -------------------------------------------------------------------[INFO] Total time: 16 seconds[INFO] Finished at: Tue Jul 17 11:00:00 IST 2012[INFO] Final Memory: 20M/89M[INFO] -------------------------------------------------------------------执行完后,咱们能够在 C:/MVN 文件夹下看到 trucks 我的项目,查看我的项目的目录构造: ...

September 8, 2021 · 2 min · jiezi

关于maven:第十二篇-Maven-项目文档之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 我的项目文档本章节咱们次要学习如何创立 Maven 我的项目文档。 比方咱们在 C:/MVN 目录下,创立了 consumerBanking 我的项目,Maven 应用上面的命令来疾速创立 java 我的项目: mvn archetype:generate -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false批改 pom.xml,增加以下配置(如果没有的话): <project> ...<build><pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.7</version> </plugin> </plugins> </pluginManagement></build> ...</project>不然运行 mvn site 命令时呈现 java.lang.NoClassDefFoundError: org/apache/maven/doxia/siterenderer/DocumentContent 的问题, 这是因为 maven-site-plugin 版本过低,降级到 3.3+ 即可。 关上 consumerBanking 文件夹并执行以下 mvn 命令。C:\MVN\consumerBanking> mvn siteMaven 开始生成文档: [INFO] Scanning for projects...[INFO] -------------------------------------------------------------------[INFO] Building consumerBanking[INFO]task-segment: [site][INFO] -------------------------------------------------------------------[INFO] [site:site {execution: default-site}][INFO] artifact org.apache.maven.skins:maven-default-skin: checking for updates from central[INFO] Generating "About" report.[INFO] Generating "Issue Tracking" report.[INFO] Generating "Project Team" report.[INFO] Generating "Dependencies" report.[INFO] Generating "Continuous Integration" report.[INFO] Generating "Source Repository" report.[INFO] Generating "Project License" report.[INFO] Generating "Mailing Lists" report.[INFO] Generating "Plugin Management" report.[INFO] Generating "Project Summary" report.[INFO] -------------------------------------------------------------------[INFO] BUILD SUCCESSFUL[INFO] -------------------------------------------------------------------[INFO] Total time: 16 seconds[INFO] Finished at: Wed Jul 11 18:11:18 IST 2012[INFO] Final Memory: 23M/148M[INFO] -------------------------------------------------------------------关上 C:\MVN\consumerBanking\target\site 文件夹。点击 index.html 就能够看到文档了。Maven 应用一个名为 Doxia的文档解决引擎来创立文档,它能将多种格局的源码读取成一种通用的文档模型。要为你的我的项目撰写文档,你能够将内容写成上面几种罕用的,可被 Doxia 转化的格局。 ...

September 7, 2021 · 1 min · jiezi

关于maven:第十篇-Maven-引入外部依赖之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 引入内部依赖如果咱们须要引入第三方库文件到我的项目,该怎么操作呢? pom.xml 的 dependencies 列表列出了咱们的我的项目须要构建的所有内部依赖项。 要增加依赖项,咱们个别是先在 src 文件夹下增加 lib 文件夹,而后将你工程须要的 jar 文件复制到 lib 文件夹下。咱们应用的是 ldapjdk.jar ,它是为 LDAP 操作的一个帮忙库:而后增加以下依赖到 pom.xml 文件中: <dependencies> <!-- 在这里增加你的依赖 --> <dependency> <groupId>ldapjdk</groupId> <!-- 库名称,也能够自定义 --> <artifactId>ldapjdk</artifactId> <!--库名称,也能够自定义--> <version>1.0</version> <!--版本号--> <scope>system</scope> <!--作用域--> <systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath> <!--我的项目根目录下的lib文件夹下--> </dependency> </dependencies>pom.xml 文件残缺代码如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.bank</groupId> <artifactId>consumerBanking</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>consumerBanking</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>ldapjdk</groupId> <artifactId>ldapjdk</artifactId> <scope>system</scope> <version>1.0</version> <systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath> </dependency> </dependencies> </project>

September 7, 2021 · 1 min · jiezi

关于maven:第十一篇-Maven-项目模板之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 我的项目模板Maven 应用 archetype(原型) 来创立自定义的我的项目构造,造成 Maven 我的项目模板。 在后面章节咱们学到 Maven 应用上面的命令来疾速创立 java 我的项目:mvn archetype:generate什么是 archetype?archetype 也就是原型,是一个 Maven 插件,精确说是一个我的项目模板,它的工作是依据模板创立一个我的项目构造。咱们将应用 quickstart 原型插件创立一个简略的 java 应用程序。 应用我的项目模板让咱们关上命令控制台,跳转到 C:\> MVN 目录并执行以下 mvn 命令:C:\MVN> mvn archetype:generate Maven 将开始解决,并要求抉择所需的原型: [INFO] Scanning for projects...[INFO] Searching repository for plugin with prefix: 'archetype'.[INFO] -------------------------------------------------------------------[INFO] Building Maven Default Project[INFO]task-segment: [archetype:generate] (aggregator-style)[INFO] -------------------------------------------------------------------[INFO] Preparing archetype:generate...600: remote -> org.trailsframework:trails-archetype (-)601: remote -> org.trailsframework:trails-secure-archetype (-)602: remote -> org.tynamo:tynamo-archetype (-)603: remote -> org.wicketstuff.scala:wicket-scala-archetype (-)604: remote -> org.wicketstuff.scala:wicketstuff-scala-archetype Basic setup for a project that combines Scala and Wicket,depending on the Wicket-Scala project. Includes an example Specs test.)605: remote -> org.wikbook:wikbook.archetype (-)606: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-glassfish (-)607: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-spring (-)608: remote -> org.xwiki.commons:xwiki-commons-component-archetype (Make it easy to create a maven project for creating XWiki Components.)609: remote -> org.xwiki.rendering:xwiki-rendering-archetype-macro (Make it easy to create a maven project for creating XWiki Rendering Macros.)610: remote -> org.zkoss:zk-archetype-component (The ZK Component archetype)611: remote -> org.zkoss:zk-archetype-webapp (The ZK wepapp archetype)612: remote -> ru.circumflex:circumflex-archetype (-)613: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)614: remote -> sk.seges.sesam:sesam-annotation-archetype (-)Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 203:按下 Enter 抉择默认选项 (203:maven-archetype-quickstart)。Maven 将询问原型的版本 ...

September 7, 2021 · 3 min · jiezi

关于maven:第九篇-Maven-构建-项目测试之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 构建 & 我的项目测试在上一章节中咱们学会了如何应用 Maven 创立 Java 利用。接下来咱们要学习如何构建和测试这个我的项目。 进入 C:/MVN 文件夹下,关上 consumerBanking 文件夹。你将看到有一个 pom.xml 文件,代码如下: Maven 构建 & 我的项目测试在上一章节中咱们学会了如何应用 Maven 创立 Java 利用。接下来咱们要学习如何构建和测试这个我的项目。进入 C:/MVN 文件夹下,关上 consumerBanking 文件夹。你将看到有一个 pom.xml 文件,代码如下:<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.bank</groupId> <artifactId>consumerBanking</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>consumerBanking</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies></project>从以上 xml代码中,可知 Maven 曾经增加了 JUnit 作为测试框架。 默认状况下 Maven 增加了一个源码文件 C:\MVN\consumerBanking\src\main\java\com\companyname\bank\App.java 和一个测试文件 C:\MVN\consumerBanking\src\test\java\com\companyname\bank\AppTest.java。 关上命令控制台,跳转到 C:\MVN\consumerBanking 目录下,并执行以下 mvn 命令开始构建我的项目: C:\MVN\consumerBanking>mvn clean package[INFO] Scanning for projects...[INFO] -------------------------------------------------------------------[INFO] Building consumerBanking[INFO] task-segment: [clean, package][INFO] -------------------------------------------------------------------[INFO] [clean:clean {execution: default-clean}][INFO] Deleting directory C:\MVN\consumerBanking\target.........[INFO] [jar:jar {execution: default-jar}][INFO] Building jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESSFUL[INFO] ------------------------------------------------------------------------[INFO] Total time: 2 seconds[INFO] Finished at: Tue Jul 10 16:52:18 IST 2012[INFO] Final Memory: 16M/89M[INFO] ------------------------------------------------------------------------执行完后,咱们曾经构建了本人的我的项目并创立了最终的 jar 文件,上面是要学习的要害概念: ...

September 7, 2021 · 1 min · jiezi

关于maven:第八篇-Maven-构建-Java-项目之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 构建 Java 我的项目Maven 应用原型 archetype 插件创立我的项目。要创立一个简略的 Java 利用,咱们将应用 maven-archetype-quickstart 插件。 在上面的例子中,咱们将在 C:\MVN 文件夹下创立一个基于 maven 的 java 利用我的项目。 命令格局如下: mvn archetype:generate "-DgroupId=com.companyname.bank" "-DartifactId=consumerBanking" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DinteractiveMode=false"参数阐明: -DgroupId: 组织名,公司网址的反写 + 项目名称-DartifactId: 我的项目名-模块名-DarchetypeArtifactId: 指定 ArchetypeId,maven-archetype-quickstart,创立一个简略的 Java 利用-DinteractiveMode: 是否应用交互模式生成的文件夹构造如下:各个文件夹阐明:在 C:\MVN\consumerBanking\src\main\java\com\companyname\bank 文件夹中,能够看到一个 App.java,代码如下: App.javapackage com.companyname.bank; /** * Hello world! * */public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); }}关上 C:\MVN\consumerBanking\src\test\java\com\companyname\bank 文件夹,能够看到 Java 测试文件 AppTest.java。 AppTest.javapackage com.companyname.bank; import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite; /** * Unit test for simple App. */public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); }}接下来的开发过程中咱们只须要依照下面表格中提到的构造搁置好,其余的事件 Maven 帮咱们将会搞定。 ...

September 7, 2021 · 1 min · jiezi

关于maven:第七篇-Maven-插件之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 插件Maven 有以下三个规范的生命周期: clean:我的项目清理的解决default(或 build):我的项目部署的解决site:我的项目站点文档创立的解决每个生命周期中都蕴含着一系列的阶段(phase)。这些 phase 就相当于 Maven 提供的对立的接口,而后这些 phase 的实现由 Maven 的插件来实现。 咱们在输出 mvn 命令的时候 比方 mvn clean,clean 对应的就是 Clean 生命周期中的 clean 阶段。然而 clean 的具体操作是由 maven-clean-plugin 来实现的。 所以说 Maven 生命周期的每一个阶段的具体实现都是由 Maven 插件实现的。 Maven 实际上是一个依赖插件执行的框架,每个工作实际上是由插件实现。Maven 插件通常被用来: 创立 jar 文件创立 war 文件编译代码文件代码单元测试创立工程文档创立工程报告插件通常提供了一个指标的汇合,并且能够应用上面的语法执行: <code>mvn [plugin-name]:[goal-name]</code>例如,一个 Java 工程能够应用 maven-compiler-plugin 的 compile-goal 编译,应用以下命令:<code>mvn compiler:compile</code>插件类型Maven 提供了上面两种类型的插件:实例咱们曾经在咱们的例子中大量应用了 maven-antrun-plugin 来输入数据到管制台上。请查看 Maven - 构建配置文件 章节。让咱们用一种更好的形式了解这部分内容,在 C:\MVN\project 目录下创立一个 pom.xml 文件。 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.companyname.projectgroup</groupId><artifactId>project</artifactId><version>1.0</version><build><plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>id.clean</id> <phase>clean</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>clean phase</echo> </tasks> </configuration> </execution> </executions> </plugin></plugins></build></project>接下来,关上命令终端跳转到 pom.xml 所在的目录,并执行上面的 mvn 命令。mvn cleanMaven 将开始解决并显示 clean 生命周期的 clean 阶段。 ...

September 7, 2021 · 1 min · jiezi

关于maven:第六篇-Maven-仓库之Spring-Cloud直播商城-b2b2c电子商务技术总结

Maven 仓库在 Maven 的术语中,仓库是一个地位(place)。 Maven 仓库是我的项目中依赖的第三方库,这个库所在的地位叫做仓库。 在 Maven 中,任何一个依赖、插件或者我的项目构建的输入,都能够称之为构件。 Maven 仓库能帮忙咱们治理构件(次要是JAR),它就是搁置所有JAR文件(WAR,ZIP,POM等等)的中央。 Maven 仓库有三种类型: 本地(local)地方(central)近程(remote)本地仓库Maven 的本地仓库,在装置 Maven 后并不会创立,它是在第一次执行 maven 命令的时候才被创立。 运行 Maven 的时候,Maven 所须要的任何构件都是间接从本地仓库获取的。如果本地仓库没有,它会首先尝试从近程仓库下载构件至本地仓库,而后再应用本地仓库的构件。 默认状况下,不论Linux还是 Windows,每个用户在本人的用户目录下都有一个路径名为 .m2/respository/ 的仓库目录。 Maven 本地仓库默认被创立在 %USER_HOME% 目录下。要批改默认地位,在 %M2_HOME%\conf 目录中的 Maven 的 settings.xml 文件中定义另一个门路。 <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>C:/MyLocalRepository</localRepository></settings>当你运行 Maven 命令,Maven 将下载依赖的文件到你指定的门路中。 地方仓库Maven 地方仓库是由 Maven 社区提供的仓库,其中蕴含了大量罕用的库。 地方仓库蕴含了绝大多数风行的开源Java构件,以及源码、作者信息、SCM、信息、许可证信息等。一般来说,简略的Java我的项目依赖的构件都能够在这里下载到。 地方仓库的要害概念: 这个仓库由 Maven 社区治理。不须要配置。须要通过网络能力拜访。要浏览地方仓库的内容,maven 社区提供了一个 URL:http://search.maven.org/#browse。应用这个仓库,开发人员能够搜寻所有能够获取的代码库。 近程仓库如果 Maven 在地方仓库中也找不到依赖的文件,它会进行构建过程并输入错误信息到控制台。为防止这种状况,Maven 提供了近程仓库的概念,它是开发人员本人定制仓库,蕴含了所须要的代码库或者其余工程中用到的 jar 文件。 举例说明,应用上面的 pom.xml,Maven 将从近程仓库中下载该 pom.xml 中申明的所依赖的(在地方仓库中获取不到的)文件。 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.projectgroup</groupId> <artifactId>project</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>com.companyname.common-lib</groupId> <artifactId>common-lib</artifactId> <version>1.0.0</version> </dependency> <dependencies> <repositories> <repository> <id>companyname.lib1</id> <url>http://download.companyname.org/maven2/lib1</url> </repository> <repository> <id>companyname.lib2</id> <url>http://download.companyname.org/maven2/lib2</url> </repository> </repositories></project>Maven 依赖搜寻程序当咱们执行 Maven 构建命令时,Maven 开始依照以下程序查找依赖的库: ...

September 7, 2021 · 1 min · jiezi

关于maven:Maven依赖去哪儿找

1. 前言maven是作为Javer日常开发中必不可少的工具,然而很多人对于它的应用也只是仅限于的几个性能。 前几天在应用一个依赖总是说找不到该依赖,然而在地方仓库中确实存在该构建。这个问题让我很困惑,忽然发现对于maven这个优良构建工具的应用也只是浮于外表。痛定思痛,于是就有了这篇简短的总结。 对于maven依赖程序的搜寻,网上七嘴八舌,那么假相到底是怎么样的呢?2. 筹备依据咱们的开发教训,应用maven能够配置多个仓库,先来看看咱们最相熟的一个。 关上咱们的settings.xml文件,一开始是一个最纯净的配置文件: 能够看到,只是配置了一个镜像地址和一个本地仓库的门路,这也是咱们第一次应用maven时大多数教程中会提到的一点-批改mirror为国内的一个地址。 当初咱们创立一个maven的工程,而后看看它的依赖查找程序是怎么的? 我创立了一个mvn-dep文件夹,在这外面创立我的项目所须要的文件,为了简略,我就应用maven cli来搭建一个简略的我的项目,应用的命令如下: mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=true -DgroupId=com.watertreestar -DartifactId=mvn-dep -Dversion=1.0 -Dpackage=com.watertreestar创立好当前咱们的我的项目构造如下: <img align="left" height="300" src="https://cdn.jsdelivr.net/gh/watertreestar/CDN@master/picimage-20210826222721918.png"> 接下来看一下不同的配置下依赖查找的门路 3. 依赖查找摸索应用上一步创立的我的项目,并在下面的根底settings.xml配置文件上做批改,察看依赖查找的优先级。 在操作之前,咱们在我的项目的pom.xml中曾经蕴含了一个依赖就是fastjson <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.78</version></dependency>咱们先确保本地仓库中该版本的junit不存在,应用rm命令来删除它: rm -rf ~/.m2/repository/com/alibaba/fastjson 3.1 不批改的状况咱们应用下面的setings.xml文件,不做任何批改,执行mvn compile命令,输入如下: 能够看出,maven是从咱们配置的central镜像-阿里云镜像中拉取依赖 3.2 没有配置地方仓库镜像当初咱们把settings文件中的mirror配置删除,就成了一个赤裸裸的配置: <?xml version="1.0" encoding="UTF-8"?><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"> <pluginGroups></pluginGroups> <proxies></proxies> <localRepository>/Users/young/.m2/repository</localRepository></settings>这种状况下,依赖会从哪儿获取呢 能够看到,是从默认的地方仓库中查找和下载依赖。 依据下面的后果能够看到优先级: 特定仓库reporitory的镜像mirror > settings中配置的仓库repository3.3 我的项目配置仓库repository当初咱们把仓库的配置还原到最后的状态,如下:<?xml version="1.0" encoding="UTF-8"?><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"> <pluginGroups></pluginGroups> <proxies></proxies> <localRepository>/Users/young/.m2/repository</localRepository> <mirrors> <mirror> <id>settings-mirror</id> <url>https://maven.aliyun.com/repository/public</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors></settings>而后在第二节中创立的我的项目pom.xml文件中增加一个repository配置,咱们应用了一个sonatype的maven仓库 以后的我的项目pom.xml配置如下: <dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.78</version> </dependency></dependencies><repositories> <repository> <id>pom_repository</id> <name>sonatype</name> <url>https://repository.sonatype.org/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository></repositories>执行mvn compile命令,输入如下: ...

August 29, 2021 · 1 min · jiezi

关于maven:Maven-让你的编译和打包自动化

工具与资源核心帮忙开发者更加高效的工作,提供围绕开发者全生命周期的工具与资源https://developer.aliyun.com/... 插件篇1. Maven中指定Java的编译版本和源文件编码方式Maven默认编译版本是JDK1.5,在很多时候,发现有些代码报错,又找不到起因,很有可能是没有配置JDK版本。就如有一次我遇到的问题:定义全局异样解决类继承HandlerInterceptorAdapter时候,preHandle办法下面有@Override就始终报错,点开HandlerInterceptorAdapter源码,显著是有这个办法,起初发现JDK版本的问题,按如下办法设置好后,谬误解决了。 1. 1 第一种形式在我的项目的pom.xml文件中指定,然而此办法只对该我的项目无效,如下图红框所示,设置为JDK1.8。 <build> <plugins> <!-- 设置JDK版本 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>1. 2 第二种形式在maven装置目录的conf文件夹下,批改settings.xml文件,在profiles节点里增加如下设置,如下图所示,设置为JDK1.8,此办法对所有Maven我的项目无效。 <profile> <id>JDK1.8</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <encoding>UTF-8</encoding> </properties></profile>2. maven 多模块打包,jar包和war输入到指定文件夹maven多模块我的项目构造示例 父工程的pom中增加spring-boot-maven-plugin 的 outputDirectory<properties> <!-- properties中定义jar包的保留门路--> <project.jar.output.directory>D:\JT\java\workspace\webvr-end\deploy</project.jar.output.directory></properties> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- 文件名以及输入门路--> <configuration> <!-- 1.0.5示意版本号--> <finalName>${project.artifactId}-1.0.5</finalName> <outputDirectory>${project.jar.output.directory}</outputDirectory> </configuration> </plugin> <!-- 跳过启动测试 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </pluginManagement></build>输入成果在父工程下,执行mvn clean package -Dmaven.test.skip=true ...

August 27, 2021 · 1 min · jiezi

关于maven:maven仓库优先级

仓库分类仓库次要分类: 本地仓库:本地磁盘, 不须要启动服务,默认门路~/.m2/repository近程仓库:启动了一个仓库服务过程,提供寄存、拉取jar包的能力镜像仓库:能够了解为缓存,跟指定的源仓库保持一致其余概念: 私服:就是一个近程仓库,只不过离咱们比拟近,个别在局域网内地方仓库:也是一个近程仓库,寰球共享,离咱们比拟远聚合仓:把两个仓库的资源合并在一个仓库里事实中的产品: nexus,既能够作为私服,同时也提供镜像的能力别离创立一个host类型的和一个代理类型的仓库,而后创立一个聚合仓,在拉取时从代理仓拉去,在deploy时deploy到host仓 应用上的问题如何正确配置mirrors?如何正确配置私服(近程仓)?正确姿态这部分次要分三点 在pom中配置近程仓库在settings中配置近程仓库正确应用mirror前两点配置近程仓,也是配置私服在pom中配置近程仓库在pom.xml的repositories标签中能够配置多个近程仓库,maven如果发现本地仓库没有的依赖都会尝试从近程仓库拉取,按程序并发申请多个近程仓库 <project> <repositories> </repositories></project>在settings中配置近程仓库如果我的项目工程多了,每个我的项目都要在pom中配置近程仓库,繁琐、反复在settings.xml的profiles标签中配置多个近程仓库,成果和在pom配置多个近程仓时一样的 <settings> <profiles> <profile> <id>common</id> <repositories> <repository> <id>alimaven</id> <name>aliyun maven</name> <url>https://maven.aliyun.com/repository/central</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>common</activeProfile> </activeProfiles></settings>正确应用mirror增加阿里的镜像,留神不要应用<mirrorOf>*</mirrorOf> <settings> <mirrors> <mirror> <id>nexus-aliyun</id> <name>Nexus aliyun</name> <mirrorOf>central</mirrorOf> <url>https://maven.aliyun.com/repository/central</url> </mirror> </mirrors><settings>对于mirrorOf的作用当近程仓(不论你是在pom还是在settings中配置的)被镜像配置匹配上的时候,理论应用的将是镜像仓 对于应用<mirrorOf>*</mirrorOf>的坑如果在mirrors中的第一个mirrorOf应用了*,并且没有应用其余排除表达式,将会导致前面的mirror生效,因为maven只会应用第一个匹配上的mirror 如何解决无奈下载依赖 (示例)环境: pom.xml没有配置任何近程仓settings.xml只加了mirrorOf central 映射到 阿里镜像假如我的项目须要用到依赖 <dependency> <groupId>cascading.avro</groupId> <artifactId>avro-scheme</artifactId> <version>2.1.2</version> </dependency>执行mvn clean package -DskipTests触发拉取依赖失败 在地方仓库搜寻该jar包抉择版本后有提醒this artifact is located at Spring Plugins repository (https://repo.spring.io/plugins-release/) 阐明这个jar包没有公布到地方仓库,而是在一个叫Spring Plugins的仓库中 解决办法就是增加近程仓,在pom中或者settings中增加都能够

August 26, 2021 · 1 min · jiezi

关于maven:构建工具之Maven的使用一

一、前言对于开发一个Java我的项目,上线之前会通过编译,测试,打包,部署这几个构建过程,如果文件较少,咱们能够应用java-->javac-->jar这些命令去实现上述的构建流程。然而当工程越来越大,文件越来越多。Java原生的命令就显得顾此失彼,力不居心了。Maven基于POM治理jar包依赖,通过本身的生命周期实现我的项目的构建流程。具体构建原理可自行百度/谷歌。本文次要为大家分享一些比拟实用的maven应用技巧。 二、配置技巧1. 多办公环境开发配置技巧在公司办公时,依赖包加载会用公司的私服;在家办公时,依赖包加载会用阿里/网易等国内镜像。办公环境切换时,咱们想通过简略的形式切换,而不是每次都更改maven的settings配置文件,怎么办呢?可参考如下计划: <settings> <profile> <id>company</id> <repositories> <repository> <id>nexus</id> <name>nexus-repositories</name> <url>http://xxxx.xxxx.xxx:xxxx/nexus/content/repositories</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> <profile> <id>home</id> <repositories> <repository> <id>aliyun</id> <name>central</name> <url>https://maven.aliyun.com/repository/central</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> </profile> <activeProfiles> <activeProfile>company</activeProfile> <activeProfile>home</activeProfile> </activeProfiles></settings>配置完之后,idea会在侧边栏呈现可选框,点击相应的办公环境即可,再次打包即可。如下图: 2. 构建日志输入配置技巧打包时,咱们会留神到构建日志会输入到屏幕,如果工程比拟大,相应的大量日志也会输入。那有没有方法能够调整输入的日志级别的,答案是有的,可参考上面的三种计划: 编辑mvn执行文件 ${MAVEN_HOME}/bin/mvn 新增一行配置MAVEN_OPTS="-Dorg.slf4j.simpleLogger.defaultLogLevel=warn"maven装置目录下:conf/logging/simplelogger.properties 批改输入日志级别org.slf4j.simpleLogger.defaultLogLevel=warn在执行mvn命令的时候应用参数 -q,不过这样只能输入error信息mvn clean package -DskipTests -q3. 文件过滤打包配置技巧咱们有时心愿maven打包时只把某些资源文件打入jar包,而并不是所有的文件,此时咱们能够在POM文件做如下配置: <!--配置Maven 对resource文件 过滤 --> <resources> <resource> <directory>src/main/resources</directory> <!-- 打包时,只加载aa.properties和bb.xml --> <includes> <include>**/aa.properties</include> <include>**/bb.xml</include> </includes> <filtering>true</filtering> </resource> </resources>4. 离线开发的配置技巧有时处于平安思考咱们须要在断网的环境下进行开发,例如生产环境。此时不能连贯外网依赖如何加载呢?如何进行开发呢?maven提供了离线模式,前提是须要将下载好依赖包上传到内网环境并装置maven等相干工具,可参考如下两种计划: ...

August 17, 2021 · 1 min · jiezi

关于maven:windows环境安装Maven

1.下载文件1.1 筹备工作: Maven下载地址 1.2: 这里抉择3.6.3版本 1.3: 抉择二进制文件(binaries),别抉择错了,不是source(源码) 1.4: 抉择apache-maven-3.6.3-bin.zip下载 1.5: 将下载的文件解压(记住这个门路) 2.环境变量配置2.1: 我的电脑(右键--->属性) 2.2: 抉择高级零碎设置 2.3: 抉择环境变量 2.4: 在零碎变量新增一个变量 变量名: MAVEN_HOME变量值: apache-maven-3.6.3-bin.zip 的解压的门路 win + R 输出cmd mvn -version 呈现版本号则装置胜利,如果失败尝试重启电脑. 3.配置Maven应用阿里云镜像3.1: 在解压下的文件夹--->新建文件夹(这里就是当前jar包寄存的地位) repository 3.2: 批改Maven的配置文件(门路在conf包下) settings.xml 3.3: 增加本地库门路(照着下面正文的抄下来)在settings.xml 54行左右 3.4: 批改阿里云镜像,下载jar包速度更快.留神放在<mirrors>标签外面,settings.xml 160行左右 <!-- 阿里云仓库 --> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> <!--默认的地方仓库--> <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> <!-- 地方仓库1 --> <mirror> <id>repo1</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo1.maven.org/maven2/</url> </mirror> <!-- 地方仓库2 --> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> ...

August 6, 2021 · 1 min · jiezi

关于maven:Gradle-将-Java-类库发布到-Maven-中心仓库

废话少说,先说几个网址: SonatypeGradleGitHub这篇文章就从零开始,应用 Gradle 7 将 Java 类库公布到 Maven 核心仓库,并应用GitHub Action实现公布 release 时主动推送。 注册 sonatype这个不用说了吧,关上https://issues.sonatype.org/注册一个账号就行了 公布 issue注册当前登录 Sonatype,公布一条 issue Summary:轻易填填就行了,反正我填的是我的项目名。Group Id:填写类库的Group Id,留神如果为独立域名,对方会要求验证域名所有权(验证TXT记录),对方收到 Issue 后会揭示你增加的。Project URL:填我的项目网址,或者 GitHub 地址。SCM url:如果我的项目放 GitHub 上,就填 GitHub 地址加上.git就这样提交就行了,缓缓期待回复(品上面那张图,半小时都不到就能够了!) 你会看到上面这个没有啥用的回复: 批改build.gradle配置文件注 1:我应用的 Gradle 版本为最新的 7.1.1,其余版本请自行尝试。 注 2:我的 Gradle 配置文件为 Groovy 版的,Kotlin DSL 版请自行转换。 首先在plugins中增加maven-publish和signing插件, plugins { id 'maven-publish' id 'signing'}而后在配置文件最初增加以下内容: java { withJavadocJar() withSourcesJar()}javadoc { options.addStringOption("charset", "UTF-8") if (JavaVersion.current().isJava9Compatible()) { options.addBooleanOption('html5', true) }}publishing { publications { mavenJava(MavenPublication) { artifactId = '构件名称' from components.java pom { name = '我的项目名' description = '我的项目形容' url = '我的项目URL' licenses { license { name = '许可证名称' url = '许可证地址' } } developers { developer { id = '开发者ID' name = '开发者名' email = '开发者邮箱' } } scm { connection = 'scm:git:git://github.com/path/to/repo.git' developerConnection = 'scm:git:ssh://github.com/path/to/repo.git' url = 'https://github.com/path/to/repo' } } } } repositories { maven { name = "OSSRH" if (project.version.toString().endsWith("-SNAPSHOT")) { url = "https://s01.oss.sonatype.org/content/repositories/snapshots" } else { url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" } credentials { username = findProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME") password = findProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD") } } }}signing { sign(publishing.publications.mavenJava)}次要内容为: ...

July 27, 2021 · 2 min · jiezi

关于maven:jar包冲突解决

maven依赖准则 间接依赖最短优先: a>b>c和a>e>f>d>c, 则优先应用前者申明程序优先: 若门路长度雷同, 则先申明优先.抵触起因maven有传递依赖机制, 当A依赖B, 引入A依赖时, 则mave在解析A时连同B一起引入. A>B>C>G21(guava 20.0)E>F>G20(guava 21.0)假如pom引入A和E, 则maven会引入guava 20.0而不是G21, 当程序中调用G21新加的办法或类时, 会跑出ClassNotFoundException/NoSuchMethodError 排查 通过类/办法查找, 如能够找到则存在jar包抵触, 找不到则可能是短少jar包, 引入即可.应用mvn dependency:tree [-Dverbose -Dincludes=groupId:artifactId], 或DIEA插件Maven Helper查看依赖树查看查找类中版本和maven依赖中的版本是否雷同示例报错: Caused by: java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable查找类, 存在, 则jar包抵触, 援用的spring-core 4.2.2查看依赖树, 引入的是spring-core3.0.7, 与类版本不统一 找到抵触pom, 增加排除

July 19, 2021 · 1 min · jiezi

关于maven:Maven-POM配置-译文

POM原文: https://maven.apache.org/guid... 构建我的项目开发Java的过程中可能会应用很多依赖包,来自第三方的或者由本人搭建的Maven仓库。依赖包之间的版本兼容治理是开发中一个辣手的问题。Maven将所有依赖无关的信息记录在pom.xml文件上,而后主动地下载和构建这些依赖包。 什么是POMPOM全称Project Object Model(我的项目对象模型),是Maven的根本单元。这个XML文件蕴含了所有对于我的项目配置的信息,这些信息将用于Maven构建我的项目。它蕴含了一些默认值,target文件夹是build目录,src/main/java文件夹是源代码目录,src/test/java是测试目录。运行Maven时,Maven会首先寻找POM所在的文件夹,而后获取其中的配置信息,最初执行它将要做的工作。 Super POMPOM文件之间能够有依赖关系,一个POM文件能够应用它继承的POM文件的配置信息。所有的POM文件都隐式地继承于super-POM,super-POM的内容可见:https://maven.apache.org/ref/... Minimal POM (最小POM)一个最小的无效POM文件须要蕴含以下的配置信息 project:配置信息的根 modelVersion:设置为4.0.0 groupId:我的项目的组id artifactId:我的项目的id version:我的项目的版本 以下是一个示例 <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version></project>组id,id和版本组成一个我的项目残缺的非法名称,例如组id为com.xich.app,我的项目id为super-teacher,版本号为1.0.0.RELEASE。那么一个非法的残缺的项目名称为com.xich.app:super-teacher:1.0.0.RELEASE。 下面的最小POM配置没有告知Maven要执行什么指标(goal),那么Maven就会执行默认的指标(记住,这些默认的配置来自POM文件继承的super-POM)。默认指标就是将目前这个我的项目打包为一个jar包。 最小POM配置也没有阐明Maven仓库的地址,super-POM中申明了仓库为https://repo.maven.apache.org/maven2,那么它就会从这个仓库中下载所需的包。 我的项目继承POM中可被合并的元素包含: dependencies:依赖 developers and contributors:开发者和贡献者 plugin lists:插件列表 plugin executions with matching ids:带有id的插件执行 plugin configuration:插件配置 resources:资源 你能够应用parent元素申明继承。 例子以最小POM中的POM为例子,即com.mycompany.app:my-app:1,咱们引入另一个我的项目:com.mycompany.app:module-alpha:1 我的项目的目录构造: . |--module-alpha | --pom.xml --pom.xml能够看到module-alpha.pom.xml是com.mycompany.app:module-alpha:1的POM配置。 当初,咱们想让com.mycompany.app:my-app:1作为父我的项目,那么module-alpha的pom.xml应该为 <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>com.mycompany.app</groupId> <artifactId>module-alpha</artifactId> <version>1</version></project>其中relativePath指定了POM的所在位置 我的项目整合 (Project Aggregation)我的项目整合相似我的项目继承,但它不是指定模块的POM作为父级POM,而是指定父级POM中的模块进行整合。这样,父级我的项目就晓得它的模块有哪些,如果一个Maven指令在父我的项目中执行,那么Maven指令同样会执行在父我的项目的模块中。 具体用法: 将父级POM打包进pom在父级POM中指定其子模块的目录例子仍然是取下面的两个POM作为示例 位于.\pom.xml的com.mycompany.app:my-app:1 <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version></project>位于.\module-alpha\pom.xml的com.mycompany.app:module-alpha:1 ...

July 12, 2021 · 1 min · jiezi

关于maven:史上最全部署Nexus

一、什么是Maven私服私服是指公有服务器,是架设在局域网的一种非凡的近程仓库,目标是代理近程仓库及部署第三方构建。有了私服之后,当 Maven 须要下载构件时,间接申请私服,私服上存在则下载到本地仓库;否则,私服申请内部的近程仓库,将构件下载到私服,再提供给本地仓库下载 二、Maven装置1.下载地址http://maven.apache.org/download.cgi 2. 服务器装置jdk环境肯定要依照Jdk而不是jre yum install java-1.8.0-openjdk-devel.x86_64参考:https://www.cnblogs.com/yaun1498078591/p/10368884.html 3.装置Maven3.装置Maven[root@localhost ~]# cd /data/tools/maven[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz[root@localhost src]# tar -zxvf apache-maven-3.8.1-bin.tar.gz4.配置零碎环境变量[root@localhost jvm]# vim /etc/profileexport JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-2.el8.x86_64export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport PATH=$PATH:$JAVA_HOME/binexport MAVEN_HOME=/data/tools/maven/apache-maven-3.8.1export PATH=$PATH:$MAVEN_HOME/bin[root@localhost jvm]# source /etc/profile5.验证Maven是否装置胜利执行命令:mvn -vApache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)Maven home: /data/tools/maven/apache-maven-3.8.1Java version: 1.8.0_292, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-2.el8.x86_64/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux", version: "4.18.0-301.1.el8.x86_64", arch: "amd64", family: "unix"三、装置Nexus1.下载地址https://www.sonatype.com/download-oss-sonatype 2. 源码装置[root@localhost jvm]# cd /data/tools/maven/[root@localhost src]# wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.11.0-01-unix.tar.gz[root@localhost src]# tar -zxvf nexus-3.11.0-01-unix.tar.gz[root@localhost src]# mv nexus-3.11.0-01 /usr/local/nexus3. 启动nexus默认端口8081,如果要批改端口能够在etc/nexus-default.properties配置中批改启动: ...

June 22, 2021 · 1 min · jiezi

关于maven:汇总Maven常用依赖包

将开发过程罕用的maven依赖汇总下来,不必每次都去maven仓库查问,能够节俭很多工夫。 - pom.xml模板<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.1</version> <relativePath/> </parent> <groupId>com.daoge.seata</groupId> <artifactId>spring-boot-samples</artifactId> <name>spring-boot-samples</name> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version> <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <springboot.verison>2.5.1</springboot.verison> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>${springboot.verison}</version> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>${maven-deploy-plugin.version}</version> <configuration> <skip>true</skip> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> </plugins> </build></project>- springboot<properties> <springboot.verison>2.5.1</springboot.verison></properties><dependencies> <!--spring-boot--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>${springboot.verison}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${springboot.verison}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>${springboot.verison}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${springboot.verison}</version> </dependency></dependencies>- db<properties> <mysql-connector.version>5.1.49</mysql-connector.version> <druid.version>1.2.6</druid.version> <mybatis.version>2.2.0</mybatis.version> <mybatis-plus.version>3.4.3</mybatis-plus.version> <tk-mybatis.version>2.1.5</tk-mybatis.version> <lombok.version>1.18.20</lombok.version> </properties><dependencies> <!--db--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql-connector.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>${mybatis-plus.version}</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>${tk-mybatis.version}</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency></dependencies>- nacos<properties> <nacos.version>0.2.3</nacos.version> <nacos-client.verison>1.1.3</nacos-client.verison> </properties><dependencies> <!--nacos client--> <dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>${nacos-client.verison}</version> </dependency></dependencies>- dubbo<properties> <apache.dubbo.version>3.0.0</apache.dubbo.version></properties><dependencies> <!--dubbo--> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>${apache.dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>${apache.dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-registry-nacos</artifactId> <version>${apache.dubbo.version}</version> </dependency></dependencies>- seata<properties> <seata-spring-boot-starter.version>1.4.2</seata-spring-boot-starter.version> <seata-all.version>1.4.2</seata-all.version></properties><dependencies> <!-- seata --> <dependency> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> <version>${seata-spring-boot-starter.version}</version> <exclusions> <exclusion> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> <version>${seata-all.version}</version> </dependency></dependencies> - netty<properties> <netty-all.version>4.1.32.Final</netty-all.version></properties><dependencies> <!--netty--> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>${netty-all.version}</version> </dependency></dependencies>- utils<properties> <apache.httpclient.version>4.5</apache.httpclient.version> <alibaba.spring-context-support.version>1.0.11</alibaba.spring-context-support.version> <fastjson.version>1.2.47</fastjson.version> <commons-lang3.version>3.9</commons-lang3.version> <guava.version>27.0.1-jre</guava.version></properties><dependencies> <!--httpclient--> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${apache.httpclient.version}</version> </dependency> <!-- 应用Spring拆卸形式时可选 --> <dependency> <groupId>com.alibaba.spring</groupId> <artifactId>spring-context-support</artifactId> <version>${alibaba.spring-context-support.version}</version> </dependency> <!-- fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- commons-lang3 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <!-- guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency></dependencies>微信公众号 - 稻哥说编程(RedCode1024)博主,从事程序开发10余年,分享有用的行业解决方案,欢送留言交换。 ...

June 19, 2021 · 2 min · jiezi

关于maven:linux-下的安装maven

linux装置maven查看发行版本 lsb_release -a 我的机子是centos8.3.2011 的 阿里云买的去maven官网下载对应的版本 (linux) http://maven.apache.org/downl...将下载好的 maven压缩文件置于指定的目录下 我这边是 /mydata/maven 下解压之 tar -zxvf apache-maven-3.6.3-bin.tar.gz解压当前配置环境变量 vi /etc/profile# 最初追加这两行export MAVEN_HOME=/mydata/maven/apache-maven-3.6.3export PATH=$MAVEN_HOME/bin:$PATH# 从新加载配置文件source /etc/profilemvn -v 能够看到如下输入就代表胜利了 [root@aliyun maven]# mvn -vApache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)Maven home: /mydata/maven/apache-maven-3.6.3Java version: 1.8.0_292, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4.x86_64/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux", version: "4.18.0-240.22.1.el8_3.x86_64", arch: "amd64", family: "unix"最初有童鞋说maven官网进不去那就用这个开源中国的地址去下载吧清华大学开源镜像 参考 https://www.zhihu.com/search?...

June 16, 2021 · 1 min · jiezi

关于maven:Maven的安装与在Eclipse中新建Maven工程

1、下载地址:http://maven.apache.org/downl...解压下载包2、配置环境变量新建变量MAVEN_HOME编辑Path变量,新增maven bin门路3、查看是否装置胜利运行cmd,输出mvn --version呈现版本号内容,则示意装置胜利啦!其余:批改配置文件4、批改本地默认仓库门路关上maven conf目录下的settings.xml文件,搜寻localRepository,将该标签放在正文外,并替换本人本地的仓库地址,如5、批改地方(近程)仓库地址,搜寻mirror,将该标签值换成阿里云的地址: <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> 以上,就是maven装置须要留神的事项了。 另,补充Eclipse同学们,配置Maven与新建一个新maven事项的教程:1、配置Maven,找到导航windows->preferences,找到Maven下的Installations,点击add增加maven装置门路:点击finish,勾选新增加进来的maven我的项目:2、配置maven配置文件:找到maven下的user settings,点击browse,找到conf目录下的settings.xml文件: 新建一个MAVEN我的项目1、File->new->other 搜寻maven,抉择maven project:搜寻webapp输出工程的坐标点击finish,实现了!

June 11, 2021 · 1 min · jiezi

关于maven:发布Jar到maven中央仓库

账号注册首先咱们要先注册sonatype账号,拜访地址sonatype输出必须的内容就能够胜利注册一个账号,不过对明码就有一些非凡的平安要求,正确注册就能够了。 sonatype工单新建工单点击新建按钮,项目选择open的那个,问题类型抉择new project,概要,形容轻易写就ok了新建实现后如下图: 增加txt记录如上边的图所示,它为了验证你是域名的所有者,会让你去解析一条txt记录。两种计划选一种就能够了,我这里抉择的是增加一条txt的记录,如下图所示,我这里是不分明规定,提交了两个工单,所以增加了两条记录,最初其中一个工单被认为是反复提交,已敞开。其中记录值填写你的工单地址,下图中框住的局部,主机记录就是jira tiket.这里txt解析的值起源就是你的问题url,如下:解析完后就能够再期待审核了,我的大略是凌晨3点进行的审核,通过当前会有邮件告诉,工单下边也有评论,此时咱们就能够筹备公布咱们的jar包了。 com.iminling has been prepared, now user(s) yslao can:Publish snapshot and release artifacts to https://oss.sonatype.orgHave a look at this section of our official guide for deployment instructions:https://central.sonatype.org/pages/ossrh-guide.html#deploymentPlease comment on this ticket when you've released your first component(s), so we can activate the sync to Maven Central.Depending on your build configuration, this might happen automatically. If not, you can follow the steps in this section of our guide:https://central.sonatype.org/pages/releasing-the-deployment.html公布筹备gpg装置mac装置gpg这里利用brew进行装置 ...

June 3, 2021 · 5 min · jiezi

关于maven:如果快速将maven项目转成gradle项目

这里有一个快捷的操作,如下: 首先关上Terminal,切换到pom所在的文件夹下执行如下命令gradle init --type pom失常后果如下 H:\springcloudproject\springcloud\api-gateway>gradle init --type pomStarting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details> Task :initMaven to Gradle conversion is an incubating feature.BUILD SUCCESSFUL in 31s2 actionable tasks: 2 executed期待执行结束查看目录发现没有变动,稍等或被动刷新一下目录就能够了

May 18, 2021 · 1 min · jiezi

关于idea:idea-maven-多model无法互相引用

景象:idea报错,一个model无奈找到另一个model的依赖,执行maven install后,能够找到依赖,然而找到的是其余model装置后的jar包,而非我的项目中的源代码。剖析代码起因:model版本号通过profile中的properties管制,而非最外层properties管制,造成idea无奈辨认到本地对应版本的model,从而去仓库中寻找依赖。剖析:只有当依赖的其余model版本号定义为常量,或变量是定义properties中(非profile)中时,能力会寻找其余model源码

April 21, 2021 · 1 min · jiezi

关于gradle:使用gradle插件发布项目到nexus中央仓库

简介Sonatype 提供了一个叫做开源软件资源库托管Open Source Software Repository Hosting (OSSRH) 的工具,帮忙咱们来不便的将我的项目公布到核心仓库中。 然而这个工具和咱们的我的项目构建是割裂的,尤其是在CI集成构建中,很难做到自动化。 Gradle是一个很好的构建工具,灵便而又弱小,可不可以间接在Gradle中的工作中间接构建和上传到地方仓库或者其余自定义的nexus仓库中呢?答案是必定的。 Gradle Nexus Publish Plugin历史明天要给大家介绍的gradle插件名字叫做Gradle Nexus Publish Plugin,最近才公布了1.0.0版本,有小伙伴可能要问了,gradle进去这么久了,最近才有这样的插件吗? 其实不然,咱们来讲一下gradle Nexus公布插件的历史。 2015年,Marcin Zajączkowski创立了gradle-nexus-staging-plugin,该插件可在Nexus存储库管理器中敞开和开释staging存储库。应用这个插件就能够间接从代码中将Gradle我的项目公布到Maven Central仓库。多年来,它曾经在寰球各地被多个我的项目所采纳。 然而这个插件存在一个小问题: 因为Gradle公布过程中的技术限度,因而须要应用启发式技术来跟踪隐式创立的staging存储库,对于给定状态的多个存储库,通常会公布失败。尤其是在继续集成服务Travis CI在2019年末更改其网络架构之后,这个插件问题就更多了。 基于这个问题,马克·菲利普(Marc Philipp)创立了另外一个插件Nexus Publish Plugin,该插件丰盛了Gradle中的公布机制,能够显式创立staging存储库并间接向其公布(上传)组件。 通常咱们须要将这两个插件一起应用,然而,一个性能须要应用到两个插件还是会让用户感到困惑。所以Gradle Nexus Publish Plugin在2020/2021年应运而生了,它的目标就是合并下面两个插件的性能。 插件的应用在gradle中应用该插件很简略,首先须要引入这个插件: plugins { id("io.github.gradle-nexus.publish-plugin") version "«version»"}留神,这个插件必须在 Gradle 5.0 或者之后的版本应用,并且在根我的项目中引入。接下来,咱们须要定义要公布的仓库,如果是通过Sonatype's OSSRH Nexus公布到Maven的地方仓库,那么须要增加sonatype(),如下所示: nexusPublishing { repositories { sonatype() }}在sonatype()中,实际上定义了nexusUrl 和 snapshotRepositoryUrl。 公布到地方仓库是须要用户名明码的,咱们须要设置sonatypeUsername 和 sonatypePassword 这两个我的项目的属性。一种办法是在~/.gradle/gradle.properties 中进行配置,或者设置 ORG_GRADLE_PROJECT_sonatypeUsername 和 ORG_GRADLE_PROJECT_sonatypePassword 这两个环境变量。 或者,能够间接在sonatype 中进行定义: nexusPublishing { repositories { sonatype { username = "your-username" password = "your-password" } }}最初,调用publishToSonatype和 closeAndReleaseSonatypeStagingRepository就能够别离公布到Sonatype和敞开并公布到地方仓库了。 ...

April 19, 2021 · 1 min · jiezi

关于maven:已解决maven项目srcmainjava下包含静态文件无法被编译问题

maven工程有专门的resources文件夹存储动态资源,但有时咱们有将动态文件与class并列的状况,此时须要在maven中增加如下配置: <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> </includes> </resource> <resource> <directory>src/resources</directory> </resource></resources>示意蕴含动态文件的门路。另,对于java读取动态资源,分为绝对路径及相对路径两种形式绝对路径示意以src为根目录,以“/”为起始字符的文件内容。而相对路径示意与以后类并列的地位,不须要加“/”。 private static String PROPERTIESFILE = "conn.properties";public static void main(String[] args) throws IOException { Pool pool = new Pool(); pool.load();}private void load() throws IOException { // 相对路径 InputStream is = this.getClass().getResourceAsStream("" + PROPERTIESFILE); // 绝对路径 InputStream is = this.getClass().getResourceAsStream("/" + PROPERTIESFILE); // 另一种形式 - 此办法会遍历门路寻找,所以不须要加“/” InputStream is = ClassLoader.getSystemResourceAsStream(PROPERTIESFILE); Properties p = new Properties(); p.load(is); System.out.println(p.getProperty("hello"));}

April 7, 2021 · 1 min · jiezi

关于maven:maven常用命令集合收藏大全

公众号:MarkerHub,网站:https://markerhub.com小Hub领读:maven的命令其实很多,这里收集了很多罕用的,珍藏珍藏,说不定用到哈~ 作者:ydlmlh原文:http://ydlmlh.iteye.com/blog/...抽了点工夫,整顿了一些 maven 常用命令参数,以便参考;参考了 maven 官网和网上其余一些 maven 追随者的文件,不在此一一列举,但表示感谢! mvn 命令参数mvn -v, --version 显示版本信息; mvn -V, --show-version 显示版本信息后继续执行 Maven 其余指标; mvn -h, --help 显示帮忙信息; mvn -e, --errors 管制 Maven 的日志级别, 产生执行谬误相干音讯; mvn -X, --debug 管制 Maven 的日志级别, 产生执行调试信息; mvn -q, --quiet 管制 Maven 的日志级别, 仅仅显示谬误; mvn -Pxxx 激活 id 为 xxx 的 profile (如有多个,用逗号隔开); mvn -Dxxx=yyy 指定 java 全局属性; mvn -o , --offline 运行 offline 模式, 不联网更新依赖; mvn -N, --non-recursive 仅在以后我的项目模块执行命令, 不构建子模块; ...

March 9, 2021 · 3 min · jiezi

关于maven:Maven-搭建一个基本的-SpringBoot-工程

一,新建 springboot 工程springboot 工程的创立形式有好几种,能够在官网提供的工程创立页面进行创立、也能够在 eclipse 中下载插件创立 springboot 工程、或者是在创立了 Maven 工程当前将 springboot 工程依赖的 jar 包引入。当然,做 springboot 工程比拟好用的还有 IDEA 等等,总之,对于工程的创立能够抉择本人比拟罕用的形式来创立工程,这里不再赘述。 二,Maven 工程依赖配置咱们应用 eclipse IDE 创立的 springboot 工程目录构造如上面所示。 接下来,配置好 Maven 工程所须要的依赖 jar 包,关上 pom.xml 文件增加依赖。 <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring-restdocs.version>2.0.2.RELEASE</spring-restdocs.version> <com.alibaba.druid>1.1.10</com.alibaba.druid> <swagger.version>2.9.2</swagger.version> <mybatis-plus.version>3.0.2</mybatis-plus.version> <shiro.version>1.3.2</shiro.version> </properties> <dependencies> <!--SpringBoot Web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--SpringBoot Mybatis--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> <!--Mybatis plus--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${ mybatis-plus.version}</version> </dependency> <!--Mybatis 分页插件--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>${ mybatis-plus.version}</version> </dependency> <!--分页辅助配置--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.6</version> </dependency> <!--MYSQL数据库驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--配置数据连接池--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${ com.alibaba.druid}</version> </dependency> <!--json--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.28</version> </dependency> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <!--sl4j--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <!--Shiro 权限框架--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>${ shiro.version}</version> </dependency> <!--shiro-web依赖--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> <version>${ shiro.version}</version> </dependency> <!--shiro-spring 反对--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>${ shiro.version}</version> </dependency> <!-- shiro 缓存 --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-ehcache</artifactId> <version>1.4.0</version> </dependency> <!--Swagger配置、反对在线接口文档--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${ swagger.version}</version> </dependency> <!--Swagger UI 配置--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${ swagger.version}</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <!-- Mybatis 逆向工程 --> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.4.0</version> </dependency> </dependencies> <build> <plugins> <!-- SpringBoot Maven 插件 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- Mybatis 逆向工程 Maven 插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <configuration> <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> </plugin> </plugins> </build></project>三,工程配置在 springboot 的工程中,我的项目相干局部的配置基本上在 application.yml 文件中都能够实现配置。 ...

February 26, 2021 · 3 min · jiezi

关于maven:gradle中的增量构建

简介在咱们应用的各种工具中,为了晋升工作效率,总会应用到各种各样的缓存技术,比如说docker中的layer就是缓存了之前构建的image。在gradle中这种以task组合起来的构建工具也不例外,在gradle中,这种技术叫做增量构建。 增量构建gradle为了晋升构建的效率,提出了增量构建的概念,为了实现增量构建,gradle将每一个task都分成了三局部,别离是input输出,工作自身和output输入。下图是一个典型的java编译的task。 以上图为例,input就是指标jdk的版本,源代码等,output就是编译进去的class文件。 增量构建的原理就是监控input的变动,只有input发送变动了,才从新执行task工作,否则gradle认为能够重用之前的执行后果。 所以在编写gradle的task的时候,须要指定task的输出和输入。 并且要留神只有会对输入后果产生变动的能力被称为输出,如果你定义了对初始后果齐全无关的变量作为输出,则这些变量的变动会导致gradle从新执行task,导致了不必要的性能的损耗。 还要留神不确定执行后果的工作,比如说同样的输出可能会失去不同的输入后果,那么这样的工作将不可能被配置为增量构建工作。 自定义inputs和outputs既然task中的input和output在增量编译中这么重要,本章将会给大家解说一下怎么才可能在task中定义input和output。 如果咱们自定义一个task类型,那么满足上面两点就能够应用上增量构建了: 第一点,须要为task中的inputs和outputs增加必要的getter办法。 第二点,为getter办法增加对应的注解。 gradle反对三种次要的inputs和outputs类型: 简略类型:简略类型就是所有实现了Serializable接口的类型,比如说string和数字。文件类型:文件类型就是 File 或者 FileCollection 的衍生类型,或者其余能够作为参数传递给 Project.file(java.lang.Object) 和 Project.files(java.lang.Object...) 的类型。嵌套类型:有些自定义类型,自身不属于后面的1,2两种类型,然而它外部含有嵌套的inputs和outputs属性,这样的类型叫做嵌套类型。接下来,咱们来举个例子,如果咱们有一个相似于FreeMarker和Velocity这样的模板引擎,负责将模板源文件,要传递的数据最初生成对应的填充文件,咱们考虑一下他的输出和输入是什么。 输出:模板源文件,模型数据和模板引擎。 输入:要输入的文件。 如果咱们要编写一个实用于模板转换的task,咱们能够这样写: import java.io.File;import java.util.HashMap;import org.gradle.api.*;import org.gradle.api.file.*;import org.gradle.api.tasks.*;public class ProcessTemplates extends DefaultTask { private TemplateEngineType templateEngine; private FileCollection sourceFiles; private TemplateData templateData; private File outputDir; @Input public TemplateEngineType getTemplateEngine() { return this.templateEngine; } @InputFiles public FileCollection getSourceFiles() { return this.sourceFiles; } @Nested public TemplateData getTemplateData() { return this.templateData; } @OutputDirectory public File getOutputDir() { return this.outputDir; } // 下面四个属性的setter办法 @TaskAction public void processTemplates() { // ... }}下面的例子中,咱们定义了4个属性,别离是TemplateEngineType,FileCollection,TemplateData和File。后面三个属性是输出,前面一个属性是输入。 ...

February 17, 2021 · 3 min · jiezi

关于maven:深入了解gradle和maven的区别

简介gradle和maven都能够用来构建java程序,甚至在某些状况下,两者还能够相互转换,那么他们两个的共同点和不同点是什么?咱们如何在我的项目中抉择应用哪种技术呢?一起来看看吧。 gradle和maven的比拟尽管gradle和maven都能够作为java程序的构建工具。然而两者还是有很大的不同之处的。咱们能够从上面几个方面来进行剖析。 可扩展性Google抉择gradle作为android的构建工具不是没有理由的,其中一个十分重要的起因就是因为gradle够灵便。一方面是因为gradle应用的是groovy或者kotlin语言作为脚本的编写语言,这样极大的进步了脚本的灵活性,然而其本质上的起因是gradle的基础架构可能反对这种灵活性。 你能够应用gradle来构建native的C/C++程序,甚至扩大到任何语言的构建。 相对而言,maven的灵活性就差一些,并且自定义起来也比拟麻烦,然而maven的我的项目比拟容易看懂,并且上手简略。 所以如果你的我的项目没有太多自定义构建需要的话还是举荐应用maven,然而如果有自定义的构建需要,那么还是投入gradle的怀抱吧。 性能比拟尽管当初大家的机子性能都比拟强劲,如同在做我的项目构建的时候性能的劣势并不是那么的迫切,然而对于大型项目来说,一次构建可能会须要很长的工夫,尤其对于自动化构建和CI的环境来说,当然心愿这个构建是越快越好。 Gradle和Maven都反对并行的我的项目构建和依赖解析。然而gradle的三个特点让gradle能够跑的比maven快上一点: 增量构建gradle为了晋升构建的效率,提出了增量构建的概念,为了实现增量构建,gradle将每一个task都分成了三局部,别离是input输出,工作自身和output输入。下图是一个典型的java编译的task。 以上图为例,input就是指标jdk的版本,源代码等,output就是编译进去的class文件。 增量构建的原理就是监控input的变动,只有input发送变动了,才从新执行task工作,否则gradle认为能够重用之前的执行后果。 所以在编写gradle的task的时候,须要指定task的输出和输入。 并且要留神只有会对输入后果产生变动的能力被称为输出,如果你定义了对初始后果齐全无关的变量作为输出,则这些变量的变动会导致gradle从新执行task,导致了不必要的性能的损耗。 还要留神不确定执行后果的工作,比如说同样的输出可能会失去不同的输入后果,那么这样的工作将不可能被配置为增量构建工作。 构建缓存gradle能够重用同样input的输入作为缓存,大家可能会有疑难了,这个缓存和增量编译不是一个意思吗? 在同一个机子上是的,然而缓存能够跨机器共享.如果你是在一个CI服务的话,build cache将会十分有用。因为developer的build能够间接从CI服务器下面拉取构建后果,十分的不便。 Gradle守护过程gradle会开启一个守护过程来和各个build工作进行交互,长处就是不须要每次构建都初始化须要的组件和服务。 同时因为守护过程是一个始终运行的过程,除了能够防止每次JVM启动的开销之外,还能够缓存我的项目构造,文件,task和其余的信息,从而晋升运行速度。 咱们能够运行 gradle --status 来查看正在运行的daemons过程。 从Gradle 3.0之后,daemons是默认开启的,你能够应用 org.gradle.daemon=false 来禁止daemons。 咱们能够通过上面的几个图来直观的感受一下gradle和maven的性能比拟: 应用gradle和maven构建 Apache Commons Lang 3的比拟: 应用gradle和maven构建小我的项目(10个模块,每个模块50个源文件和50个测试文件)的比拟: 应用gradle和maven构建大我的项目(500个模块,每个模块100个源文件和100个测试文件)的比拟: 能够看到gradle性能的晋升是非常明显的。 依赖的区别gralde和maven都能够本地缓存依赖文件,并且都反对依赖文件的并行下载。 在maven中只能够通过版本号来笼罩一个依赖项。而gradle更加灵便,你能够自定义依赖关系和替换规定,通过这些替换规定,gradle能够构建非常复杂的我的项目。 从maven迁徙到gradle因为maven呈现的工夫比拟早,所以基本上所有的java我的项目都反对maven,然而并不是所有的我的项目都反对gradle。如果你有须要把maven我的项目迁徙到gradle的想法,那么就一起来看看吧。 依据咱们之前的介绍,大家能够发现gradle和maven从实质上来说就是不同的,gradle通过task的DAG图来组织工作,而maven则是通过attach到phases的goals来执行工作。 尽管两者的构建有很大的不同,然而得益于gradle和maven相识的各种约定规定,从maven移植到gradle并不是那么难。 要想从maven移植到gradle,首先要理解下maven的build生命周期,maven的生命周期蕴含了clean,compile,test,package,verify,install和deploy这几个phase。 咱们须要将maven的生命周期phase转换为gradle的生命周期task。这里须要应用到gradle的Base Plugin,Java Plugin和Maven Publish Plugin。 先看下怎么引入这三个plugin: plugins { id 'base' id 'java' id 'maven-publish'}clean会被转换成为clean task,compile会被转换成为classes task,test会被转换成为test task,package会被转换成为assemble task,verify 会被转换成为check task,install会被转换成为 Maven Publish Plugin 中的publishToMavenLocal task,deploy 会被转换成为Maven Publish Plugin 中的publish task。 ...

February 10, 2021 · 2 min · jiezi

关于maven:新建模块pomxml文件上有个横线

这个货色是因为以前建过同名的模块,而后模块删除了

January 28, 2021 · 1 min · jiezi

关于SegmentFault:IDEA简介下载安装及简单配置

IDEA简介IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一。尤其在智能代码助手、代码主动提醒、重构、J2EE反对、Ant、JUnit、CVS整合、代码审查、 翻新的GUI设计等方面的性能能够说是超常的。IDEA是JetBrains公司的产品,这家公司总部位于捷克共和国的首都布拉格,开发人员以谨严著称的东欧程序员为主。 IDEA下载IDEA官网下载地址依据不同的操作系统,下载不同平台下的IDEA,如下: IDEA装置装置之前肯定要装置JDK并且配置(环境变量JAVA_HOME,path)下载安装版须要装置能力失常应用.启动程序,并依照提醒装置即可,这里以windows版本(.exe)来做演示,如下: 找到下载好的安装包并执行,即关上装置向导,在第一个界面点击Next即可: 在抉择装置门路的界面,能够自行确定IntelliJ IDEA的装置目录,并点击Next即可 勾选64-bit launcher,并点击Next即可,在装置实现后在桌面创立一个IntelliJ IDEA的快捷方式 抉择开始菜单文件夹,放弃默认即可,点击Install 期待进度条读完,装置实现,点击finish即可勾选Run IntelliJ IDEA则点击finish后主动运行,如未勾选则在桌面上寻找IntelliJ IDEA x64手动点击运行 第一次运行时,会关上设置界面,首页会进入用户协定界面,勾选并点击continue持续即可 点击Don't Send即可,示意不会给IntelliJ IDEA分享数据 设置IntelliJ IDEA默认的应用格调,Darcula 暗色/Light 亮色,依据爱好自行抉择就好,并点击Next: IntelliJ IDEA中默认默认装置了一些罕用的插件使得开发人员能更加便捷的进行开发,以后页面为默认装置好的插件,间接下一步即可.Customize 为自行定制,Disable All 为禁用所有,不倡议进行批改,间接点击Next即可: IntelliJ IDEA中除了上述插件外还能够装置其余插件,不倡议在这个页面装置,如果当前有应用到的中央,咱们间接在设置页面装置即可,间接点击Start using IntelliJ IDEA,让咱们开始应用IntelliJ IDEA吧: 因为咱们演示的案例是IntelliJ IDEA中Ultimate版本即免费版,如果曾经购买,则间接在以后页面输出激活材料即可,如未购买能够选中Evaluate for free 进入免试应用界面,点击Evaluate并开始试用:以上咱们的装置IntelliJ IDEA就已实现 IDEA配置IntelliJ IDEA中没有workspace(工作空间)的概念,Eclipse的工作空间中能够有很多我的项目,这些我的项目可能毫无关系.IntelliJ IDEA中Project(我的项目)就相当于Eclipse中的工作空间,Module(模块)相当于eclipse中的我的项目,然而倡议多个模块之间是有业务关系的. 因为之前抉择的款式格调为Darcula 暗色,所以咱们以这种护眼模式的格调进行阐明,图中依据序号顺次点选操作即可:首先咱们点击 Create New Project 来创立一个新的我的项目:这里因为咱们还没有决定创立一个什么样的我的项目,所以咱们首先创立一个空的我的项目,抉择Empty Project:在Project Name中输出项目名称,这里我输出的是workspace(这里随便起名即可,没有特殊要求);Project location中是咱们我的项目门路即我的项目保留的地位(本人抉择就好):创立好我的项目后顺次点击左上角File → Settings进入设置选项 Appearance(外观设置)theme主题配置(IntelliJ Light/Window 10 Light/Darcula/High contrast)操作界面的字体款式及大小(这里的界面指的是工具栏) Editor(编辑区设置)通过Ctrl + 鼠标滚轮调节字体大小 主动导包 auto import ...

January 20, 2021 · 1 min · jiezi

关于maven:如何使用GitHub创建Maven私有仓库

参考文章https://www.cnblogs.com/liufa... https://blog.csdn.net/sunxiao... https://malalanayake.wordpres...

January 13, 2021 · 1 min · jiezi

关于maven:osx环境下maven项目编译失败

osx下maven的一个坑osx零碎maven根本都是Homebrew装置的.maven是java写的须要jre运行环境.所以Homebrew会主动帮你装openjdk. { "homebrew_version":"2.4.0-69-g67c843b-dirty", "used_options":[ ], "unused_options":[ ], "built_as_bottle":false, "poured_from_bottle":false, "installed_as_dependency":false, "installed_on_request":true, "changed_files":null, "time":1592835968, "source_modified_time":1573129938, "HEAD":"67c843b91ef272d5408fc2cb74ce8b39042ec1bf", "stdlib":null, "compiler":"clang", "aliases":[ "maven@3.6" ], "runtime_dependencies":[ { "full_name":"openjdk", "version":"13.0.2+8" } ], "source":{ "path":"/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/maven.rb", "tap":"homebrew/core", "spec":"stable", "versions":{ "stable":"3.6.3", "devel":"", "head":"", "version_scheme":0 } }}****大多数状况是相安无事的.直到遇见了 javax.xml.bind.annotation包.这个包存在于jdk8,在后续大略jdk11的时候被移除了.于是mvn package的时候呈现以下的问题. 一开始我认为是pom文件配置出了问题.前面我发现用idea的maven是能够编译的.所以代码应该是没锅的.于是我查看了一下maven的版本.果然有问题. 没错,他竟然用的是openjdk13.0.很显然和咱们的开发环境1.8产生了抵触.果决改之. 如下,把java_home改成咱们的jdk1.8 #!/bin/bash JAVA_HOME="${JAVA_HOME:-/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home}" exec "/usr/local/Cellar/maven/3.6.3_1/libexec/bin/mvn" "$@" 从新执行mvn package.编译胜利.

January 12, 2021 · 1 min · jiezi

关于maven:maven如何动态统一修改版本号

前言最近业务开发部门因为开发环境和测试环境共用一个maven私仓,导致他们开发环境的API包和测试环境的API包产生了笼罩景象。于是他们向咱们部门提出一个需要,心愿咱们能帮他们实现或者提供这么一个计划,就是我的项目自动化构建时,我的项目的版本号能跟着环境变更。比方是开发环境,则我的项目的API包版本就形如1.0-dev,如果是测试环境,则我的项目的API版本就形如1.0-test 示例演示我的项目层级如下 计划一:mvn -Denv.project.version=1.0-env注: env.project.version为自定参数变量,env为dev或者test 1、在maven我的项目的父级pom设置变量,形如下 <groupId>org.example</groupId> <artifactId>demo-parent</artifactId> <packaging>pom</packaging> <version>${env.project.version}</version> <properties> <env.project.version>1.0-SNAPSHOT</env.project.version> </properties>2、批改其子模块pom <parent> <artifactId>demo-parent</artifactId> <groupId>org.example</groupId> <version>${env.project.version}</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>module-biz</artifactId> <parent> <artifactId>demo-parent</artifactId> <groupId>org.example</groupId> <version>${env.project.version}</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>module-api</artifactId>3、执行如下命令mvn clean package -Denv.project.version=1.0-dev -DskipTests如果要打包公布到公有仓库,则执行 mvn clean deploy-Denv.project.version=1.0-dev -DskipTests4、验证从截图,能够看出达到预期的成果 计划二 maven的profile+自定参数变量1、在maven我的项目的父级pom设置变量,并增加profile,形如下 <properties> <env.project.version>1.0-SNAPSHOT</env.project.version> </properties> <profiles> <profile> <id>dev</id> <properties> <env.project.version>1.0-dev</env.project.version> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <env.project.version>1.0-test</env.project.version> </properties> </profile> </profiles>2、批改其子模块pom <parent> <artifactId>demo-parent</artifactId> <groupId>org.example</groupId> <version>${env.project.version}</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>module-biz</artifactId> <parent> <artifactId>demo-parent</artifactId> <groupId>org.example</groupId> <version>${env.project.version}</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>module-api</artifactId>3、执行如下命令mvn clean package -Ptest -DskipTests如果要打包公布到公有仓库,则执行 ...

December 25, 2020 · 1 min · jiezi

关于maven:Linux-Maven-安装与配置

传送门maven 官网地址:http://maven.apache.org/maven 下载地址:http://maven.apache.org/download.cgimaven 历史版本:https://archive.apache.org/dist/maven/maven-3/下载mavencd /usr/localwget https://archive.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gztar -zxvf apache-maven-3.2.5-bin.tar.gzmv apache-maven-3.2.5 ./maven配置环境量vim /etc/profile配置export M2_HOME=/usr/local/mavenexport PATH=...:$M2_HOME/bin:...示意在前面减少#刷新配置source /etc/profile#创立Maven本地仓库:mkdir -p /usr/data/maven/repo关上Maven的settings.xml配置文件,配置相应的仓库门路以及仓库地址vim /usr/local/maven/conf/settings.xml批改本地仓库门路:<localRepository>/usr/data/maven/local_repository</localRepository>批改国内仓库地址:<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus...</url></mirror>

December 11, 2020 · 1 min · jiezi

关于maven:SSMMavenJackson

1 Maven概述Maven是一个项目管理工具,它蕴含了一个我的项目对象模型 (Project Object Model),一组规范汇合,一个我的项目生命周期(Project Lifecycle),一个依赖管理系统(Dependency Management System),和用来运行定义在生命周期阶段(phase)中插件(plugin)指标(goal)的逻辑。当你应用Maven的时候,你用一个明确定义的我的项目对象模型来形容你的我的项目,而后Maven能够利用横切的逻辑,这些逻辑来自一组共享的(或者自定义的)插件。 maven次要是用来解决包依赖问题。 在我的项目分服务开发中,之前大家是导入jar包来引入代码,可能存在不同服务雷同性能应用不同版本,导致局部性能无奈应用。后引入maven项目管理工具,先能够将服务中的雷同性能向上抽取,造成共性依赖maven-parent,各服务中依赖继承maven-parent,对立治理依赖,方便管理和保护,防止包依赖问题。 留神:将maven-parent打成pom包< packaging>pom</packaging> 2 Jackson概述:Jackson 是一个 Java 的用来解决 JSON 格局数据的类库 三大性能: jackson-core,外围包,提供基于"流模式"解析的相干 API,它包含 JsonPaser 和 JsonGenerator。 Jackson 外部实现正是通过高性能的流模式 API 的 JsonGenerator 和 JsonParser 来生成和解析 json。jackson-annotations,注解包,提供规范注解性能;jackson-databind ,数据绑定包, 提供基于"对象绑定" 解析的相干 API ( ObjectMapper ) 和"树模型" 解析的相干 API (JsonNode);基于"对象绑定" 解析的 API 和"树模型"解析的 API 依赖基于"流模式"解析的 API。2.1 ObjectMapperJackson 最罕用的 API 就是基于"对象绑定" 的 ObjectMapper。上面是一个 ObjectMapper 的应用的简略示例。 ObjectMapper 通过 writeValue 系列办法 将 java 对 象序列化 为 json,并 将 json 存 储成不同的格局,String(writeValueAsString),Byte Array(writeValueAsString),Writer, File,OutStream 和 DataOutput。ObjectMapper 通过 readValue 系列办法从不同的数据源像 String , Byte Array, Reader,File,URL, InputStream 将 json 反序列化为 java 对象。json与对象的转化: ...

December 3, 2020 · 1 min · jiezi

关于maven:Maven-中央仓库提交Jar包全程指南

Maven 地方仓库提交Jar包全程指南本文记录一下将jar上传到maven地方仓库的全过程,文中我的项目依靠在github上,应用的是mac环境 (对于maven、jdk的环境配置不属于本文内容) <!-- more --> 1. sonatype账号申请首先咱们须要申请一个账号,地址为: https://issues.sonatype.org/secure/Signup!default.jspa 请记住这个账号的用户名 + 明码,在后续的maven的setting.xml配置文件中须要用到 账号申请结束之后,点击新建按钮(如果是因为的话,就是create),提交一个issue 我的项目:抉择Community Support - Open Source Project Repository Hosting (OSSRH)问题类型:抉择New Project概要:我的项目阐明形容:我的项目阐明GroupId: 请留神,对于github我的项目而言,前缀都是com.github,前面跟着的是你的账号名,比方我的账号是liuyueyi,所以我的groupId是 com.github.liuyueyi,如果不满足这个规定将无奈通过后续的审核Project URL: 我的项目地址,填对应的github连贯 https://github.com/liuyueyi/quick-chinese-transferSCM URL: 和下面的基本一致,只是多了一个.git基本上须要配置的货色如下图,最初点击新建即可 下面提交之后,期待审核即可 2. GPG装置在后续的上传jar包时,须要利用gpg进行签名,上面介绍一下mac的装置流程 举荐用法 macos装置能够借助homebrew来实现 brew install gpg备选计划 然而我的mac零碎比拟老,应用下面的形式装置失败,间接抛了异样,依据搜寻后果来看,不降级零碎貌似没有什么好的解决办法 上面是采纳安装包的形式,原则上倡议到官网去下载安装包,仍然是因为版本问题,最新的我也装置不上,所以找了一个历史的下载网址,(不保障这个网站上的安装包的安全性。尽管我本人用的也是它) 如有须要,能够跳转: https://sourceforge.net/p/gpgosx/docu/Download/ 我抉择的是2.2.12版本,装置结束之后,能够查看一下外面的readme文件,查看具体的装置门路 比方在我的电脑上装置门路为: /usr/local/gnupg-2.2/bin,为了方便使用,能够设置一下环境 vim ~/.bash_profile# 增加新的path门路PATH=$PATH:/usr/local/gnupg-2.2/binsource ~/.bash_profile密钥生成及公布 装置结束之后,设置咱们本人的密钥 # 生成密钥对# 输出用户名 + 邮箱,请记住这个明码,前面上传jar包的时候会用到gpg --gen-key 查看本地密钥 # 生成结束之后,查看本地密钥gpg --list-keys 上图中勾住的就是咱们的公钥id,接下来将公钥id上传到密钥服务器 ## 上传公钥gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公钥ID## 查看公钥上传状况gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公钥ID ...

December 3, 2020 · 2 min · jiezi

关于maven:Maven

Maven次要内容Maven的简介简介 Maven【[mevn]】这个词能够翻译为"专家",“外行”。 作为Apache组织中的一个颇为胜利的开源我的项目,Maven次要服务于基于java平台的我的项目构建,依赖治理和我的项目信息管理。 无论是小型的开源类库我的项目,还是大型的企业级利用; 无论是传统的瀑布式开发,还是风行的麻利开发,Maven都能大显神通。 我的项目构建 不论你是否意识到,构建(build)是每一位程序员每天都在做的工作。早上来到公司,咱们做的第一件事就是从源码库签出最新的代码,而后进行单元测试,如果测试失败,会找相干的共事一起调试,修复错误代码。 接着回到本人的工作上来,编写本人的单元测试及产品代码。 认真总结一下,咱们会发现,除了编写源代码,咱们每天有相当一部分工夫花在了编译,运行单元测试,生成文档,打包和部署等繁琐且不起眼的工作上,这就是构建。 如果咱们当初还手工这样做,那老本也太高了,于是有人用软件的办法让这一系列工作齐全自动化,使得软件的构建能够像全自动流水线一样,只须要一条简略的命令,所有繁琐的步骤都可能主动实现,很快就能失去最终后果。 我的项目构建工具 Ant构建 最早的构建工具,基于IDE, 大略是2000年有的,过后是最风行java构建工具,不过它的XML脚本编写格局让XML文件特地大。对工程构建过程中的过程管制特地好 Maven【JAVA】 我的项目对象模型,通过其形容信息来治理我的项目的构建,报告和文档的软件项目管理工具。它填补了Ant毛病,Maven第一次反对了从网络上下载的性能,依然采纳xml作为配置文件格式。Maven专一的是依赖治理,应用Java编写。 **Gradle** 属于联合以上两个的长处,它继承了Ant的灵便和Maven的生命周期治理,它最初被google作为了Android御用管理工具。它最大的区别是不必XML作为配置文件格式,采纳了DSL格局,使得脚本更加简洁。 目前市面上Ant比拟老,所以个别是一些比拟传统的软件企业公司应用,Maven应用Java编写, 是当下大多数互联网公司会应用的一个构建工具, 中文文档也比拟齐全, gradle是用groovy编写,目前比拟新型的构建工具一些初创互联网公司会应用,当前会有很大的应用空间。 Maven的四大个性依赖管理系统 Maven为Java世界引入了一个新的依赖管理系统jar包治理 jar 降级时批改配置文件即可。在Java世界中,能够用groupId、artifactId、version组成的Coordination(坐标)惟一标识一个依赖。 任何基于Maven构建的我的项目本身也必须定义这三项属性,生成的包能够是Jar包,也能够是war包或者jar包。一个典型的依赖援用如下所示: <dependency> <groupId>javax.servlet</groupId> com.baidu <artifactId>javax.servlet-api</artifactId> ueditor echarts <version>3.1.0</version></dependency> 坐标属性的了解 Maven坐标为各种组件引入了秩序,任何一个组件都必须明确定义本人的坐标。 groupId 定义以后Maven我的项目附属的理论我的项目-公司名称。(jar包所在仓库门路) 因为Maven中模块的概念,因而一个理论我的项目往往会被划分为很多模块。 比方spring是一个理论我的项目,其对应的Maven模块会有很多,如spring-core,spring-webmvc等。 artifactId 该元素定义理论我的项目中的一个Maven模块-我的项目名, 举荐的做法是应用理论项目名称作为artifactId的前缀。 比方: spring-bean、 spring-webmvc等。 version 该元素定义Maven我的项目以后所处的版本。 多模块构建 我的项目复查时 dao service controller 层拆散将一个我的项目合成为多个模块曾经是很通用的一种形式。 ...

November 30, 2020 · 5 min · jiezi

关于maven:maven多模块和依赖冲突问题汇总记录

目录 前言:明天学习和总结了一下maven的相干知识点,发现一些比拟根底的货色竟然也会遗记,这里对于一些日常工作中可能会遇到的问题进行了一下汇总。 idea怎么创立maven多module的我的项目首先理解下面是多module?一句话概括就是:一个父模块作为版本控制多个子模块,子模块负责接入到父模块当中作为整个我的项目的过程。 多Module治理我的项目的几种形式:依照单模块拆分为多个子模块,比方将MVC三层架构拆分为 xxx-service,xxx-dao,xxx-model,不过这种形式个人感觉比拟二,目前以业务模块拆分比拟多,迁徙到微服务比方用springcloude或者dubbo 的时候十分好用。依照业务模块拆分,这种模式应用的比拟多,也比拟多见。创立一个多module我的项目(idea2019.3.3版本)创立一个父pom我的项目:关上idea,抉择create new project 抉择maven我的项目,同时不选任何的预加载设置 父pom配置如下: 删除src 目录 创立子模块,引入到父pom外面同样右击我的项目工程,抉择new module,而后抉择maven,这时候会呈现父模块以及对应的子模块名称 此时在父模块外面发现引入了子模块的内容 子父模块的区别:父pom.xml文件内容:<groupId>org.zxd</groupId><artifactId>taglib</artifactId><packaging>pom</packaging><version>1.0.0</version><modules> <module>taglib-core</module></modules>分为两个局部,一个局部是父pom的申明,蕴含gourpId,artifactId,打包形式必须是pom,因为应用了聚合模型,同时在父pom外面指定版本号,子模块不填写version会默认应用父pom的version号 <modules> <module>taglib-core</module></modules>下面示意以后引入的子模块内容 子pom.xml文件内容:<!-- 援用自父pom --><parent> <artifactId>taglib</artifactId> <groupId>org.zxd</groupId> <version>1.0.0</version></parent><!-- 打包形式为jar包 --><packaging>jar</packaging><modelVersion>4.0.0</modelVersion><artifactId>taglib-core</artifactId><version>1.0.0</version>子模块之间进行相互的依赖在上面的pom中能够在任意的子模块引入对应的父模块依赖 留神因为<parent>这个标签会递归继承,所以要留神子依赖不要和依赖引入不同版本的依赖,这样容易造成抵触 <dependency> <groupId>org.zxd</groupId> <artifactId>taglib-core</artifactId> <version>1.0.0</version> <!-- 这里须要正文掉编译的作用域 --> <!--<scope>compile</scope>--></dependency>将下面的我的项目革新为spring-boot多模块我的项目:革新父pom文件:<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> <relativePath/> <!-- lookup parent from repository --></parent>parent指向springboot-started 子模块只须要引入父pom的内容 Spring boot maven plugin问题在打包spring boot我的项目时,须要应用如下插件: <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId></plugin>如果在用maven构建多模块我的项目时,不要将此插件放到parent pom中,否则如果有sub module不是spring boot利用,在打包时就会出错。只将该插件增加到是spring boot我的项目的子模块。 MAVEN依赖抵触问题:依赖的传递准则:最短门路准则最先申明准则maven的依赖引入策略最短门路准则:我有上面两个依赖jar包,A和B,他们都引入了C这个依赖,这时候如果有如下的援用 A -> C(3.3) B -> A(3.3) ...

November 22, 2020 · 2 min · jiezi

关于maven:maven项目引入本地jar包史上最详细实践方法

日期作者版本备注2020-09-27dingbinV1.0 maven引入本地jar包问题从3个层面思考: 1. IDE工具如Jetbrains IDEA思考:顺次关上IDEA的File – Project Structure – Project Settings – Modules –Dependencies 选项卡区域,点击右上角+号图标,抉择1.JARS ordirectories…,再抉择java工程根目录下的lib或libs目录下,把所有须要本地引入的jar包都多选中,而后点击OK即可。 2. Maven编译层面思考:在pom.xml文件中dependencies组件的最初局部增加如下图的本地依赖jar包。 留神scope为system示意本地的jar包。systemPath为本地门路,肯定要用${project.basedir}/结尾引入,以表通用型。 以上3个中央如此批改后,联结的成果是,mvn clean package后会target目录下生成一个lib目录,并且把所有的近程jar包和本地jar包都拷贝到lib目录下,以供前期java程序运行时找到之用。留神本地jar包会以上图中绿色框的约定的命名形式呈现在lib目录下。 上图中<addClasspath>true</addClasspath>表明会在生成的指标jar文件中MANIFEST.MF中增加classpath如下图,<classpathPrefix>lib</classpathPrefix>表明会给MANIFEST.MF中的classpath中每一个classpath加一个前缀lib.这些个性都十分重要。 因而<plugins></plugins>组件下一共有3项: 以vim 关上生成的指标jar包vi mylucenedemo.jar:后: 光标放在MANIFEST.MF上按下回车,即可看到: 此外,如果有需要的话,java工程指标jar的运行可能还依赖于一些配置文件,通过pom.xml中profiles下的profile将其拷贝到target目录下的conf目录中去:成果如下图: 3. 指标jar程序执行层面思考:接下来,就能够在java工程的根目录下执行:mvn clean install -U, 会生成如下的target目录,有用的是conf目录,lib目录和指标文件mylucenedemo.jar. 执行形式是: 在target目录下间接执行java -jar mylucenedemo.jar即可。 会主动读取以后目下的lib子目录的所有依赖jar包,包含引入的本地jar包。以及conf目录下的所有配置文件。 最初,另附示例pox.xml: pom.xml, 提取码:h1e1。

November 9, 2020 · 1 min · jiezi

关于maven:Maven使用

依赖传递在工程的依赖树上,深度越浅,越被优先选择。若两个依赖包处于依赖树上的同一层,则谁在前抉择谁总之,防止传递依赖时引起版本问题呈现的最佳实际。个别状况下,如果工程间接依赖到某一框架的多个模块,最好全副申明这些依赖模块聚合和继承Maven聚合当模块十分多的时候,想要一次构建多个我的项目,而不是到多个模块的目录下别离执行命令。Maven的聚合个性就是为该需要服务的。 <parent> <groupId>com.ts.mall</groupId> <artifactId>ts-mall</artifactId> <version>0.0.1-SNAPSHOT</version> <relativePath>../mall-dependencies/pom.xml</relativePath></parent><artifactId>mall-dependencies</artifactId><!-- 聚合模块必须为pom,否则无奈构建 --><packaging>pom</packaging><!-- modules是实现聚合的最外围配置,指定聚合的模块目录 --><modules> <module>../modules1</module> <module>../modules2</module> <module>../modules3</module></modules>继承子模块的grouopId和version,都会从父模块依赖下来。创立了一个模块不须要依赖父类的jar包,须要用Maven的依赖治理dependencyManagement来解决这个问题总结聚合是为了不便疾速构建我的项目继承是为了打消反复配置,在简化pom的同时还能促成各个模块配置的一致性。共同点是两者的packaging都是pom,聚合模块与继承关系中的父模块除了pom之外都没有理论内容。参考资料Maven实战(九)---模块聚合和继承

October 19, 2020 · 1 min · jiezi

关于maven:已解决-解决maven工程parent-version为-XXXRelease时not-found问题

在创立或引入新的maven我的项目后,偶然会提醒Project 'org.springframework.boot:spring-boot-starter-parent:2.3.0.RELEASE'这个error,pom的parent.version的value会爆红,对于此问题,以下是几个思路及解决办法: 查看此版本是否存在拼写错误,是否确定存在,尤其当应用不同的springbootstarter时。在引入我的项目后,是否执行了mvn install命令,或在idea下点击Reload All Maven Project 按钮。查看本地文件夹,查看此文件夹是否存在C:\Users\XXX\.m2\repository\org\springframework\boot\spring-boot-starter-parent\2.3.0.RELEASE将此版本改为其余失常版本,应用文件compare工具,比照报错的版本和失常版本的内容有何区别。 本次我的问题通过此方法解决经比照发现报错版本licence.url的value是http版本,而失常版本则是https版本,批改后,reload,胜利。玄学的点是,好用之后我改回http,发现仍然好用。。狐疑idea某些缓存没有更新的起因。

October 19, 2020 · 1 min · jiezi

关于maven:maven-配置maven阿里镜像

留神要在mirrors标签内 <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>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> <mirror> <id>jboss-public-repository-group</id> <mirrorOf>central</mirrorOf> <name>JBoss Public Repository Group</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> </mirror></mirrors>

September 29, 2020 · 1 min · jiezi

关于maven:入行-10-年总结作为开发必须知道的-Maven-实用技巧

Maven 介绍什么是 MavenMaven 是基于我的项目对象模型(POM project object model),能够通过一小段形容信息(配置)来治理我的项目的构建,报告和文档的软件项目管理工具,简略的说就是用来治理我的项目所须要的依赖且治理我的项目构建的工具。 Maven 的装置与配置从 Maven 官网下载压缩包,解压到本地。配置环境变量 MAVEN_HOME 为 Maven 的解压目录。增加 Maven 目录下的 bin 目录到环境变量 PATH 中。能够在 Maven 目录下的 conf/setting.xml 文件中,通过 <localRepository /> 来指定本地仓库门路。关上终端,输出 mvn -version 验证时是否胜利。Idea 中配置本地装置的 Maven 关上 Idea 的配置面板,找到 Maven 配置页。 Maven home directory:设置为本地的 Maven 门路User settings file:勾选前面的 Override 能够自定义 settings 文件,能够指向 Maven 门路下的 conf/settings.xmlLocal repository:勾选 Override 同样能够自定义仓库门路,默认会从配置的 settings 文件中读取。Maven 坐标与依赖坐标Maven 通过 groupId、artifactId、version 三个变量来惟一确定一个具体的依赖,俗称 GAV。 依赖在 pom.xml 中咱们通过 dependency 来申明坐标信息(GAV),如咱们须要申明对 4.2.6.RELEASE 版本 spring-core 包的依赖。 ...

September 23, 2020 · 7 min · jiezi

关于maven:idea创建maven报错java-errorrelease-version-5-not-supportedmac

在idea创立maven工程,运行程序时报错 Error:java:error:release version 5 not supportedError:java:Source option 5 is no longer supported.Use 6 or later呈现上述两个问题都是某个中央配置的时候版本选错了. 依照下述步骤一一 排查即可

September 20, 2020 · 1 min · jiezi

关于maven:idea创建maven报错java-errorrelease-version-5-not-supportedmac

在idea创立maven工程,运行程序时报错 Error:java:error:release version 5 not supportedError:java:Source option 5 is no longer supported.Use 6 or later呈现上述两个问题都是某个中央配置的时候版本选错了. 依照下述步骤一一 排查即可

September 20, 2020 · 1 min · jiezi

关于maven:maven-settingsxml的默认配置

<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless 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 ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder 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.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: ${user.home}/.m2/repository <localRepository>/path/to/local/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. | | 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>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</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 | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish, particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <!-- | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | might hypothetically look like: | | ... | <plugin> | <groupId>org.myco.myplugins</groupId> | <artifactId>myplugin</artifactId> | | <configuration> | <tomcatLocation>${tomcatPath}</tomcatLocation> | </configuration> | </plugin> | ... | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | anything, you could just leave off the <value/> inside the activation-property. | <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> --> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> --></settings>

September 17, 2020 · 6 min · jiezi

关于maven:mavensurefireplugin-SurefirePlugin-not-present

报错信息:[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ cm-common --- [WARNING] Error injecting: org.apache.maven.plugin.surefire.SurefirePlugin java.lang.TypeNotPresentException: Type org.apache.maven.plugin.surefire.SurefirePlugin not present 1. 起因运维更改测试maven版本 下载的maven-surefire-plugin依赖包pom文件中没有内容 2. 解决方案1) 手动指定可用maven-surefire-plugin版本 `<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7.2</version> </plugin>` 2) Maven版本回退 保障统一

September 8, 2020 · 1 min · jiezi

关于maven:稀小饭初识Maven

MavenMaven的作用:我的项目构建,依赖治理。 文章借鉴了菜鸟教程Maven相干的内容,链接为Maven教程。1、我的项目对象模型POM(Project Object Model) 蕴含4个局部: POM关系构建设置构建环境我的项目信息2、Maven的生命周期clean 革除上次构建生成的文件 1)pre-clean:执行清理前须要实现的工作2)clean:清理上一次构建生成的文件3)post-clean:执行清理后须要实现的工作default 构建我的项目,重要的phase如下: 1)validate:验证工程是否正确,所有须要的资源是否可用。2)compile:编译我的项目的源代码。3)test:应用适合的单元测试框架来测试已编译的源代码。这些测试不须要已打包和布署。4)package:把已编译的代码打包成可公布的格局,比方jar。5)integration-test:如有须要,将包解决和公布到一个可能进行集成测试的环境。6)verify:运行所有查看,验证包是否无效且达到质量标准。7)install:把包装置到maven本地仓库,能够被其余工程作为依赖来应用。8)deploy:在集成或者公布环境下执行,将最终版本的包拷贝到近程的repository,使得其余的开发者或者工程能够共享。site 建设和公布我的项目站点 1)`pre-site:生成我的项目站点之前须要实现的工作2)`site:生成我的项目站点文档3)post-site:生成我的项目站点之后须要实现的工作4)site-deploy:将我的项目站点公布到服务器3、Maven仓库仓库:我的项目所依赖的第三方库存放的地位本地(local)近程(remote)地方(central)搜寻程序:本地-->近程-->地方 4、我的项目模板Maven 应用原型 archetype插件创立自定义的我的项目构造,造成Maven我的项目模板。原型即为一个我的项目模板,例如要创立一个简略的helloworld我的项目,则执行mvn命令应用DarchetypeArtifactId=maven-archetype-quickstart参数,创立原型为maven-archetype-quickstart的我的项目。 5、构建简略的java我的项目mvn archetype:generate-DgroupId=com.companyname.bank-DartifactId=consumerBanking-DarchetypeArtifactId=maven-archetype-quickstart //我的项目原型-DinteractiveMode=false //是否交互模式,区别于批处理模式6、引入内部依赖间接在pom.xml中增加依赖的参数。 7、依赖治理Maven领有对依赖的传递机制,例如B依赖于A,C依赖于B,则C依赖A,maven会治理这种依赖传递的关系。 8 、Maven自动化部署部署步骤通常在我的项目的开发的过程中,部署包含以下步骤: 将我的项目代码提交到SVN或者其它代码库中并打上标签;从SVN下载残缺的我的项目代码;应用Maven构建利用;把构建好的WAR或JAR包文件存储到罕用的网络地位下;从网络上获取文件并部署到生产站点上;更新文档和利用版本号。主动部署maven-release-plugin插件能够实现主动部署,局部参数如下: scm配置SVN的门路,Maven将从该门路下将代码取下来。repository构建的WAR或EAR或JAR文件的地位,或者其余源码构建胜利后生成的构件的存储地位。plugin配置maven-release-plugin插件来实现主动部署过程。resources:用于排除或蕴含某些资源文件9、Maven中POM的3种关系依赖关系:<dependencies>、<dependency>标签;继承关系:<parent>标签,子pom文件能继承父pom的依赖;聚合关系:<modules>标签,将多个maven的我的项目聚合为一个大的我的项目。10、Maven的属性Maven的属性是值得占位符,如${X},可用于pom文件任何赋值的地位。

September 5, 2020 · 1 min · jiezi

关于maven:自动化构建工具Maven

一、目前框架须要的技术 二、目前的技术在开发的过程中存在的问题2.1 一个我的项目就是一个工程如果我的项目十分宏大,不适宜持续应用package来划分模块,最好是每个模块对应一个工程,利于分工协作。借助于Maven能够实现一个我的项目拆分成多个工程2.2 我的项目中须要的jar包必须手动复制、粘贴、到WEB-INF/lib目录下带来的问题是:同样的jar包文件反复呈现在不同的我的项目工程中,一方面节约存储空间,另外也让工程比拟臃肿借助Maven,能够将jar包仅仅放弃在“仓库”中,有须要应用的工程援用这个文件接口,并须要真的把jar包复制过去。2.3 jar包须要他人为咱们筹备好,或者官网下载不同技术的官网提供的jar包下载模式是形形色色。有些技术的官网就是通过Maven或者SVN等工具进行下载的。2.4 一个jar包依赖的其余jar包须要本人手动退出到我的项目中FileUpload文件上传->IO组件,commons-fileupload-1.3.jar依赖于commons-io-2.0.1.jar。所有jar之间的依赖关系,程序员自我理解,减少学习老本。Maven会主动将依赖的jar包导入进来。三、 Maven是什么Maven是一款服务于Java平台的自动化构建工具 Make->ant->Maven->Gradle3.1 Maven的构建编译过程 Java源文件(.java)->编译->字节码文件(.class)->交给JVM执行部署 一个BS我的项目最终运行并不是动静WEB自身,而是这个动静Web工程“编译的后果”动静Web工程->编译、部署->编译后果 搭建3.2 构建过程中的各个环节清理:将以前编译失去的旧的class字节码文件删除,为下一次编译做筹备编译:将Java源程序编程class字节码文件测试:自动测试,调用junit程序报告:测试程序执行的后果打包:动静web工程打成war包,Java工程打jar包装置:Maven特定的概念--将打包失去的文件复制到仓库中的指定地位部署:将动静web工程生产的war包复制到Servlet容器的指定目录下,使其能够运行。3.3 装置Maven外围程序查看JAVA_HOME环境变量解压Maven外围程序配置环境变量验证3.4 Maven的外围概念约定的目录构造POM pom.xml是Maven工程的外围配置文件坐标 由三个要害来确定,groupId、artifactId、version别离是公司或组织名+我的项目名、模块名、版本号其中坐标和仓库门路:groupId/artifactId/version/artifactId+version.jar依赖 Maven解析依赖时会到本地仓库中进行查找依赖的包 对于咱们本人开发的包,须要应用mvn install命令装置后能够进入仓库依赖的范畴 1 compile 对主程序是否无效 --无效对测试程序是否无效 --无效是否参加打包 --参加 ![compile](https://cdn.jsdelivr.net/gh/hshdexy/blogImages/imgs/compile.png)2 test 对主程序是否无效 --有效对测试程序是否无效 --无效是否参加打包 --不参加典型例子:junit3 provided 对主程序是否无效 --无效对测试程序是否无效 --无效是否参加打包 --不参加,不参加部署典型例子:servlet-api.jar ![prrvided图](https://cdn.jsdelivr.net/gh/hshdexy/blogImages/imgs/prrvided%E5%9B%BE.png)仓库 仓库的分类 本地仓库:以后电脑中部署的仓库近程仓库 私服:搭建在局域网中,为局域网中所有Maven工程服务地方仓库:架设在Internet上,为全世界的Maven工程提供服务地方仓库镜像:架设在各个大洲的,为地方仓库分担流量的,加重地方仓库的压力,更快响应用户的申请。仓库中保留的内容:仓库中保留的都是Maven工程 Maven本身所须要的插件第三方框架或工具的jar包咱们本人开发的Maven工程生命周期/插件/指标继承聚合四、Maven工程4.1 约定的目录构造1 根目录:工程名2 src目录:源码3 pom.xml文件:Maven工程的外围配置文件4 main目录:寄存主程序5 test目录:寄存测试程序6 Java目录:Java源文件7 resources目录:寄存框架或其余工具的配置文件 4.2、为什么要恪守约定的目录构造Maven负责我的项目的主动构建约定>配置>编码五、 罕用Maven命令5.1 留神:执行与构建过程相干的Maven命令,必须进入pom.xml所在的目录与构建过程相干:编译、测试、打包......5.2 罕用的命令mvn clean:清理mvn compile:编译主程序mvn test-compile:编译测试程序mvn test:执行测试mvn package:打包mvn install:安装包至仓库mvn site:生产站点六、 对于Maven联网的问题1 Maven的外围程序中仅仅定义了形象的生命周期,但具体的工作必须由特定的插件来实现,而插件自身并不蕴含在Maven的外围程序中2 当我的Maven命令须要某些插件时,Maven外围程序会首先到本地仓库中查找3 本地仓库的默认地位:C:UsersLJLRY.m2repository4 Maven外围程序如果在本地仓库中找不到须要的插件,那么会主动的到地方仓库进行下载5 如果此时无奈连贯外网,则构建失败6 批改本地默认的仓库地位

September 5, 2020 · 1 min · jiezi

关于maven:Maven

概述: Maven实质是一个项目管理工具,将我的项目开发和治理过程形象成一个我的项目对象模型(简称:POM)。 Maven是一个构建工具,由Apache开源组织奉献。下载、装置和配置环境References:Mac零碎下载、装置和配置Maven环境规范目录构造介绍:References:Maven规范目录构造介绍Maven的目录构造和传统的我的项目有所差异,上面是一个jar包通常有的目录构造。src/main/java:源代码目录 src/main/resources:资源文件目录 src/test/java:测试代码目录 src/test/resources:测试资源文件目录 这里只是局部构造,像jar或者war工程如果有源代码的个别是这个构造,但这个构造也不是必须的,不同的我的项目不同的需要也能够有不同的构造。 以下是maven具体给出的心愿的目录构造,并且应用模板创立maven我的项目也是依照这种构造,所以大家尽量恪守这种标准。上面看一个jar工程的目录构造其中有一个Maven dependencies就是所有的依赖jar包,target目录是打包生成的长期目录文件,包含了class文件,test的相干文件,及生成的jar包等,POM文件就是maven我的项目的外围配置文件

September 1, 2020 · 1 min · jiezi

关于maven:Maven报错Failed-to-execute-goal-orgapachemavenplugins

报错起因: 我的项目公布时,因为pom.xml文件中短少maven-compiler-plugin插件的依赖或者没有填加<source> 和 <target>属性导致。 maven是个项目管理工具,如果咱们不通知它咱们的代码要应用什么样的jdk版本编译的话,它就会用maven-compiler-plugin默认的jdk版本来进行解决,这样就容易呈现版本不匹配,以至于可能导致编译不通过的问题。maven的默认编译应用的jdk版本貌似很低,应用maven-compiler-plugin插件能够指定我的项目源码的jdk版本,编译后的jdk版本,以及编码。<plugin> <!-- 指定maven编译的jdk版本,如果不指定,maven3默认用jdk 1.5 maven2默认用jdk1.3 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <!-- 一般而言,target与source是保持一致的,然而,有时候为了让程序能在其余版本的jdk中运行(对于低版本指标jdk,源代码中不能应用低版本jdk中不反对的语法),会存在target不同于source的状况 --> <source>1.8</source> <!-- 源代码应用的JDK版本 --> <target>1.8</target> <!-- 须要生成的指标class文件的编译版本 --> <encoding>UTF-8</encoding><!-- 字符集编码 --> <skipTests>true</skipTests><!-- 跳过测试 --> <verbose>true</verbose> <showWarnings>true</showWarnings> <fork>true</fork><!-- 要使compilerVersion标签失效,还须要将fork设为true,用于明确示意编译版 本配置的可用 --> <executable><!-- path-to-javac --></executable><!-- 应用指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> --> <compilerVersion>1.3</compilerVersion><!-- 指定插件将应用的编译器的版本 --> <meminitial>128m</meminitial><!-- 编译器应用的初始内存 --> <maxmem>512m</maxmem><!-- 编译器应用的最大内存 --> <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument><!-- 这个选项用来传递编译器本身不蕴含然而却反对的参数选项 --> </configuration> </plugin>转自:https://blog.csdn.net/liupeifeng3514/article/details/80236077

August 27, 2020 · 1 min · jiezi

关于maven:Maven中央仓库jar包发布全流程详解

须要4步创立sonatype账号,并提交工单设置gpgmaven环境配置deploy1.创立sonatype账号,并提交工单1.1 关上 https://issues.sonatype.org 注册账号 信息都很简略,Full name轻易写个就好1.2 创立工单登陆后点击Create创立工单 而后开始工单信息的填写 其中groupId能够间接应用com.github.xxx,当然pom外面也要和这个对应上 1.2.1 如何应用集体域名作为groupId首先要买个和groupId对应的域名 例如自己的我的项目groupId为com.insistingon.binlogportal那么对应的域名就是insistingon.com设置域名的DNS配置给sonatype检测 当应用集体域名提交工单时,工单的comment外面会提醒 须要证实这个域名的所有人,有两种形式 加DNS的TXT记录重定向到你的github我的项目页面这里抉择第一种比较简单,在购买域名的服务商页面,批改下DNS记录即可。增加后即可通过验证2. 设置gpg2.1 gpg是什么?gpg是一个应用RSA算法加解密的软件有公网的公开仓库,能够上传公钥,供其余服务解密。简略说就是有公网的加解密服务sonatype要求推送的jar包要加密,并会依据信息去公网的仓库验证,胜利能力公布。2.2 装置gpgmac上间接应用brew install -v gpg装置2.3 生成公钥生成命令gpg --generate-key 执行命令后,会弹出设置passphrase的界面,就是明码,要记住,之后用到maven中生成后,会有一串字符,即为公钥的key,用于向公共仓库上传公钥 2.4 上传公钥生成后须要将公钥上传到公共服务器供sonatype验证sonatype应用的三个公共仓库地址,上传任意一个即可, http://keys.openpgp.org:11371http://keyserver.ubuntu.com:11371http://pool.sks-keyservers.net:11371上传命令gpg --keyserver http://keys.openpgp.org:11371 --send-keys 398A7FD459F278FB0069E831IK98L741C1A767A2留神 再上传时,如果只应用域名,不加端口,也能够胜利,然而sonatype验证时会提醒找不到key,起因暂未深究。3. maven环境配置之后要应用maven间接上传jar包到sonatype的仓库中须要对.m2/setting.xml和我的项目的pom.xml做一些设置3.1 将sonatype和gpg信息写入settings.xmlsonatype的信息配置在server中,供deploy的时候应用<servers> <server> <id>ossrh</id> <username>name</username> <password>password</password> </server></servers>gpg的信息设置在profile中,供maven的gpg插件应用<properties> <gpg.executable>gpg可执行命令门路</gpg.executable> <gpg.passphrase>生成时填写的passphrase</gpg.passphrase></properties>3.2 我的项目中的pom配置次要有两局部,deploy时的信息和要用到的插件3.2.1 deploy时的信息包含证书,开发者信息,仓库地址和公布地址<licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>actable</distribution> </license></licenses><developers> <developer> <name>dothetrick</name> <email>flyinthewar@126.com</email> <organization>dothetrick</organization> </developer></developers><scm> <tag>master</tag> <url>git@github.com:dothetrick/binlogportal.git</url> <connection>git@github.com:dothetrick/binlogportal.git</connection> <developerConnection>git@github.com:dothetrick/binlogportal.git</developerConnection></scm><distributionManagement> <snapshotRepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> <repository> <id>ossrh</id> <name>Nexus Release Repository</name> <url>http://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository></distributionManagement>3.2.2 要用到的maven插件要应用的插件 ...

August 26, 2020 · 1 min · jiezi

关于maven:Maven实战

Maven实战 下载地址: https://pan.baidu.com/s/1qpn2njtkit4ecGfpghJBqQ 扫码上面二维码关注公众号回复100021 获取分享码 本书目录构造如下: 前言 致谢 第1章 maven简介 1.1 何为maven 1.1.1 何为构建 1.1.2 maven是优良的构建工具 1.1.3 maven不仅仅是构建工具 1.2 为什么须要maven 1.2.1 组装pc和品牌pc 1.2.2 ide不是万能的 1.2.3 make 1.2.4 ant 1.2.5 不反复创造轮子 1.3 maven与极限编程 1.4 被误会的maven 1.5 小结 第2章 maven的装置和配置 2.1 在windows上装置maven 2.1.1 查看jdk装置 2.1.2 下载maven 2.1.3 本地装置 2.1.4 降级maven 2.2 在基于unix的零碎上装置maven 2.2.1 下载和装置 2.2.2 降级maven 2.3 装置目录剖析 2.3.1 m2_HOME 2.3.2 ~/.m2 2.4 设置http代理 2.5 装置m2eclipse 2.6 装置netbeans maven插件 2.7 maven装置最佳实际 2.7.1 设置maven_opts环境变量 2.7.2 配置用户范畴settingsxml 2.7.3 不要应用ide内嵌的maven 2.8 小结 第3章 maven应用入门 3.1 编写pom 3.2 编写主代码 3.3 编写测试代码 3.4 打包和运行 3.5 应用archetype生成我的项目骨架 3.6 m2eclipse简略应用 3.6.1 导入maven我的项目 3.6.2 创立maven我的项目 3.6.3 运行mvn命令 3.7 netbeans maven插件简略应用 3.7.1 关上maven我的项目 3.7.2 创立maven我的项目 3.7.3 运行mvn命令 3.8 小结 第4章 背景案例 第5章 坐标和依赖 第6章 仓库 第7章 生命周期和插件 第8章 聚合与继承 第9章 应用nexus创立私服 第10章 应用maven进行测试 第11章 应用hudson进行继续集成 第12章 应用maven构建web利用 第13章 版本治理 第14章 灵便的构建 第15章 生成我的项目站点 第16章 m2eclipse 第17章 编写maven插件 第18章 archetype 附录A pom元素参考 附录B settings元素参考 附录C 罕用插件列表 ...

August 11, 2020 · 1 min · jiezi

Found-Banned-Dependency

背景今天测试环境发布服务的时候,Jenkins编译报错[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-rules) @ dealapi ---[WARNING] Rule 1: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:Found Banned Dependency: ch.qos.logback:logback-classic:jar:1.2.3Found Banned Dependency: ch.qos.logback:logback-core:jar:1.2.3Use 'mvn dependency:tree' to locate the source of the banned dependencies.[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 7.126 s[INFO] Finished at: 2020-07-06T20:21:20+08:00[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce (enforce-rules) on project cuxiaoapi: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1] ...

July 7, 2020 · 1 min · jiezi