maven中怎么添加jar包不生效

如题所述

首先,检查包是否版本覆盖,比如slf4j,某些依赖于高版本,你自己选低版本,那么会被它覆盖掉。
其次,netbeans有个比较特殊地方,它与IDEA类似,配完pom.xml后,需要右键该文件选择update dependencies(Eclipse内名称,netbean已卸载不清楚,更新项目依赖)才会开始下载依赖的jar包。
再则,你用的maven仓库是私服还是官服?私服的话(sonatype-nexus),有些最新包是加载不到的。
最后,如果上述描述的问题都不存在,可仔细看下控制台输出的错误信息,以便对症下药。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-01-18
在pom.xml中添加对应的依赖代码后,如果jar包不生效,先去查看一下。maven本地的仓库中,是否正常的把jar包从maven库中 下载下来了。有时会因为网络原因,并没有下载完全,因为有这样的文件(无论是否下载完整,只要是有这个文件,maven就不会再更新),你再次更新时,他就不会再进行下载,所以要把本地库中对应的jar包的文件夹删除 ,再进行下载,有时,可能会进行多次这样的操作。
确定了 maven本地仓库中的jar包是正确后,再对工程里的jar进行刷新,和清理。
应该就可以了。。你试试。。
第2个回答  2017-05-04
 <dependency>
            <groupId>com.xxxxxx</groupId>
            <artifactId>xxxxxx</artifactId>
            <version>1.0.0</version>
        </dependency>

pom文件是不是没写对啊 或者maven 库里没有 这个文件 

添加maven jar 包需要配置pom文件 不过单独添加也是可以的 ,

第3个回答  2016-11-23
可以在pom.xml里面配呀,配上之后保存,然后maven updateproject,然后把jar把加载上,.m2就有了

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
</dependency>
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>

<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-sitemesh-plugin</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency>
<dependency>
<groupId>jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-contrib</artifactId>
<version>3.7-beta3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-examples</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
第4个回答  2016-10-16

从maven仓库 http://mvnrepository.com/ 查找对应的jar包和对应的版本,打开详情

将上图的红框里标记的内如粘贴到maven工程的pom.xml文件中 maven

就会自动从远程拉去jar包

相似回答