mavenoptional(mavenoptional不报错)
本篇文章给大家谈谈mavenoptional,以及mavenoptional不报错对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、eclipse中maven继承怎么没有索引
- 2、用maven打包war时,怎么才能不要lib下面的jar
- 3、maven version是必须的吗
- 4、如何在环境变量中配置maven环境变量
- 5、POM文件中的使用
- 6、为什么创建maven项目会报错
eclipse中maven继承怎么没有索引
eclipse中maven继承没有索引:
原因:应该是maven自动下载index组件的功能没有开启,查看
这一步很重要:
"Window"
-- "Preferences" and choose Maven in the left side.勾选Download repository index updates on
startup
解决:
"Window" --- "Show View" --- "Maven Repositories" --- "Global
Repositories"
选择 "central" click right and "Update Index"解决问题。
问题产生如下:
因为单位使用了过滤,访问Internet时,超过10M的内容就拒绝。
因为maven插知扒件在初始时,需要下载Maven的index文件,这个文件比较大,有38M多,下载不成功。
所以造成使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出:
Unable to update index for central| 。
决办法,手动握历下载索引文件,本地模拟部署中央仓库,更新索引后,关闭本地模拟部署中央仓库
1、首先手动去官网下载这两个文件,
如果不行,可以在云盘中下载, (提取码:8237),但可能不是最新的。
2、然后把这两个文件放到本地tomcat的目录中去,我是放在webapps\ROOT\maven2\.index\目录中 (这里说明一下,前面带点的文件夹不能用右键新建,要打开cmd窗口,用命令mkdir .index创建)
3、配置本地maven的索引加载环境 方式一:(推荐) 接着增加一个mirror,修改tomcat的端口号为80,这样就能直接用访问到索引 mirror
idnexus-local/id
mirrorOfcentral/mirrorOf
namenexus local/name
url;/url
/mirror
如果使用添加mirror的方式,那么可以不修改tomcat端口,因为配置了mirror后,就会代理mirrorOf中配搭皮昌置的仓库central。
方式二:直接将repo1.maven.org映射到本地127.0.0.1 central的默认的地址是:
编辑 c:\WINDOWS\system32\drivers\etc\hosts 文件,在文件中加入:
127.0.0.1 repo1.maven.org
然后修改tomcat的端口号为80,这样就能直接用访问到本地tomcat中的索引
注:127.0.0.1 为步骤2的Apache Tomcat服务器IP地址。
方式三:设置代理(这样方式没有亲自实践,网上收集)copy一个settings.xml到C:/Documents and Settings/username/.m2目录,并修改settings.xml文件,添加一个http代理:
[html] view plain copy
proxies
!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
proxy
idoptional/id
activetrue/active
protocolhttp/protocol
usernameproxyuser/username
passwordproxypass/password
hostproxy.host.net/host
port80/port
nonProxyHostslocal.net|some.host.com/nonProxyHosts
/proxy
--
proxy
idoptional/id
activetrue/active
protocolhttp/protocol
hostlocalhost/host
port8080/port
/proxy
/proxies
4、在Eclipse中,更新setting文件,打开 Maven Repositories 面板,在 Global Repositories -- central 项上,点右键,Rebuild Index 即可。
注意: 如果发现索引没有更新,请检查是否开启了启动eclipse自动更新索引。
"Window" --- "Show View" --- "Maven Repositories" --- "Global
Repositories"
选择 "central" click right and "Update Index"解决问题。
然后再次Rebuild Index 或者重启eclipse。
5、移除之前在 hosts 文件中添加的内容。
6、(可选)把Properties中Maven项的 Download repository index updates on starup 选项去除。
[img]用maven打包war时,怎么才能不要lib下面的jar
可以在每个dependency上面加optionaltrue/卖老optional。
但是如果中轮升你打的war包里面没有lib,那你的应用服务器怎么运行呢,放在tomcat/lib 下可不是个好桐侍方法
maven version是必须的吗
groupId,artifactId和version这个三组合标示依赖的具体工程,而且这个依赖工程必须是maven中心包管理范围内的。如果碰上非开源包,maven支持不了这个包,那么则有三种方法处理:1.本地安装这个插件install plugin例如:
mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1
2.创建自己的Repositories并且部署这个包,使用类似上面的deploy:deploy-file 命令3.设置scope为system,并且指定系统路径
dependency里面的classifier,用于区分从同一个pom编译出陵陵来的但是内容不同的同名包,例如同一个工程编译出两个artifact,一个支持jdk1.5一个支持jdk1.4,那么就可以使用这个来命名为jdk15和jdk14来区分,它如果出现在包名中,那么它必须跟在版本号后。还有一种情况是将一个工程的一些次要artifact附到主要artifact中,就可以使用这个来区分,例如一个工程产生source,javadoc,class三种东西,那么就可以使用不同的classifier来分别标识这些东西
dependency里面的type,默认为jar,类型,常用如:jar,ejb-client,test-jar,可以设置plugins中的extensions值为true后在增加新类型
dependency里面的scope,指定classpath,可以为:compile(默认的,compile scope在所有classpaths内有效,这些dependencies将会传播到项目中。provided:指示jdk或者某个容器可以提供他,它只在compilation和test的classpaths有效,而且不会传播的。runtime:指示这个dependency在编译过程是不必要的,但是执行需要,在test和runtime的classpaths有效,在compile的classpaths无效。test:指示这个dependency在一般程序运行是无效的,但是在test的compilation和execution是有效的,system则跟provided类似,但是这种dependency必须人工明确地制定。这种依赖不会在repository中查找。
dependency里面的systemPath:只在dependency的scope声明为system的时候才有用除,否则,build的过程将会失败。路径必须是绝对的,所以最好使用property来声明机器的特定路径。
dependency里面的optional:如果工程本身姿高是一个dependency那么就标记为optional,例如X需要A,A需要B,那么X只需要optional的B,则B在X中就是optional声明的了
dependency里面的exclusions:如果X需要A,A包含B依赖,那么X可以声明不要B依赖,只要在exclusions中声明exclusion。optional是不会install或者使用B,而尺册戚exclusion是将B从依赖树中是删除。例如appfuse不想使用hibernate,但是appfuse是集成hibernate的,所以就排除掉:
exclusions
exclusion
groupIdorg.appfuse/groupId
artifactIdappfuse-hibernate/artifactId
/exclusion
/exclusions--
如何在环境变量中配置maven环境变量
myeclipse自带maven(Maven4MyEclipse)
创建项目:
新建Web Projects项目,在新建的页面上打上maven的勾。新建的项目里会多出个pom.xml文件
为项目添加依赖包:
右键项目,选择Maven4MyEclipse--add Dependency。输入包名,maven会从中央库中查找。
创建自己的依赖包:
在pom.xml文件上右键,选择run as--maven install。该命令将项目发布到本地的资源库中。
其他项目需要用到这个资源,输入资源名称就可以找到。
手动安装maven
Maven 2.2.1为例 (3.0.3没下下来)
下载地址:
解压maven到安装的位置
如D:\
设置maven环境变量
配置maven环境之前要确定配置好了jdk的环境
maven_home=D:\apache-maven-2.2.1
PATH=%maven_home%\bin
测试maven是否成功
mvn -v
构建myeclipse项目
建一个web项目
mvn archetype:create -DgroupId=com.myframe -DartifactId=myframe -DarchetypeArtifactId=maven-archetype-webapp
-DgroupId 生成pom的groupidcom.myframe/groupid节点,本工程生成的jar包给其它工程依赖时用。
-DartifactId 生成的文件夹名,也就是Eclipse中web工程的名字
生成Eclipse项目
mvn eclipse:myeclipse
通过myeclipse导入生成的myeclipse项目
配置本地Repository
本地Repository的默认值是${user.home}/.m2/repository/,可在user configuration(${user.home}/.m2/setting.xml)中改变本地Repository
localRepositoryD:/.m2/repository/localRepository 将maven的jar仓库放在D:/.m2/repository文件夹下
maven常用命令
mvn archetype:create :创建 Maven 项目
mvn compile :编译源代码
mvn test-compile :编译测试代码
mvn test : 运行应用程序中的单元测试
mvn site : 生成项目相关信息的网站
mvn clean :清除目标目录中的生成结果
mvn package : 依据项目生成 jar 文件
mvn install :在本地 Repository 中安装 jar
mvn eclipse:eclipse :生成 Eclipse 项目文件
pom.xml文件节点介绍
project :文件的根节点 .
modelversion : pom.xml 使用的对象模型版本
groupId :创陪尺建项目的组织或团体的唯一 Id
artifactId :项目的唯一 Id, 可视为项目名
version :产品的版本号
packaging :打包物的扩展名,一般有 JAR,WAR,EAR 等
name :项目的显示名,常用于 Maven 生成的文档
url :组织的站点,常用于 Maven 生成的文档
description :项目的描述,常用于 Maven 生成的文档
classifier : 分类
outputDirectory : 定义输出文件夹
type : 相应的依赖产品包形式,如jar,war
scope : 用于限制相应的依赖范围,包括芦察高以下的几种变量
compile :默认范围,用于编译
provided:类似于编译,但支持你期待jdk或者容器提供,类似于classpath
runtime:在执行时,需要使用
test:用于test任务时使用
system:需要外在提供相应得元素。通过systemPath来取得
systemPath : 仅用于范围为system。提供相应的路径
optional : 标注可选,当项没中目自身也是依赖时。用于连续依赖时使用
还有两个问题没解决:
1.用maven构建的工程导入myeclipse中是java工程
2.myeclipse8.5自带maven插件创建的web项目怎么构建maven目录结构
3.导入的myeclipse工程没有Maven Dependencies依赖包
POM文件中的使用
当模块A有下面依赖
当模块B依赖模块A时,虚册如果不写optional会进行依赖传递,
当optional为true是,这个依赖项不会传递到B
当设置为fasle的时候,这个依赖项会传递到B
也就是模块B引用了模块A,模块B也不会有模块A中写了悉冲optionaltrue/差陆宏optional的依赖
更多详细:
为什么创建maven项目会报错
meven里面的setting文件要自己配置的,主要配置参考:
?xml version="1.0" encoding="UTF-8"?
凯好!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--
盯码铅!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/模胡settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.home}/conf/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|--
settings xmlns=""
xmlns:xsi=""
xsi:schemaLocation=" "
!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.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
interactiveModetrue/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
offlinefalse/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.
pluginGroupcom.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
idoptional/id
activetrue/active
protocolhttp/protocol
usernameproxyuser/username
passwordproxypass/password
hostproxy.host.net/host
port80/port
nonProxyHostslocal.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
iddeploymentRepo/id
usernamerepouser/username
passwordrepopwd/password
/server
--
!-- Another sample, using keys to authenticate.
server
idsiteServer/id
privateKey/path/to/private/key/privateKey
passphraseoptional; 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
idmirrorId/id
mirrorOfrepositoryId/mirrorOf
nameHuman Readable Name for this Mirror./name
url;/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
idjdk-1.4/id
activation
jdk1.4/jdk
/activation
repositories
repository
idjdk14/id
nameRepository for JDK 1.4 builds/name
url;/url
layoutdefault/layout
snapshotPolicyalways/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
| groupIdorg.myco.myplugins/groupId
| artifactIdmyplugin/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
idenv-dev/id
activation
property
nametarget-env/name
valuedev/value
/property
/activation
properties
tomcatPath/path/to/tomcat/instance/tomcatPath
/properties
/profile
--
/profiles
!-- activeProfiles
| List of profiles that are active for all builds.
|
activeProfiles
activeProfilealwaysActiveProfile/activeProfile
activeProfileanotherAlwaysActiveProfile/activeProfile
/activeProfiles
--
/settings
关于mavenoptional和mavenoptional不报错的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。