【转】IDEA中Maven报错NoClassDefFoundError_idea报错noclassdeffounderror_xiakexiaohu的博客-程序员宅基地

技术标签: Java基础学习  

这是我走的大概三天的坑,一直搞不清楚原因,今天总算把问题解决了。 
首先说问题的源头,是我使用SSM框架写j2ee程序,要使用到AOP,于是就在网上查找了如何使用maven添加AOP相关的jar包,之后配置了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</groupId>
    <artifactId>reeco</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>reeco Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <id>java.servlet.api</id>
            <name>Repository hosting the java servlet api artifacts</name>
            <url>http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <properties>
        <junit-version>4.12</junit-version>
        <spring-version>4.3.2.RELEASE</spring-version>
        <mybatis-version>3.4.1</mybatis-version>
        <mybatis-spring-version>1.3.0</mybatis-spring-version>
        <druid-version>1.0.24</druid-version>
        <fastjson-version>1.2.16</fastjson-version>
        <mysql-connection-version>5.1.6</mysql-connection-version>
        <mybatis-generator-version>1.3.2</mybatis-generator-version>
        <pagehelper-version>4.0.1</pagehelper-version>
        <slf4j-version>1.7.12</slf4j-version>
        <log4j-version>1.2.17</log4j-version>
        <jstl-version>1.2</jstl-version>
        <taglibs-version>1.1.2</taglibs-version>
        <aspectj-version>1.8.5</aspectj-version>
        <operation-version>1.0</operation-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit-version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</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-webmvc</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</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.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis-version}</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis-spring-version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid-version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson-version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-connection-version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>${pagehelper-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j-version}</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl-version}</version>
        </dependency>

        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>${taglibs-version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <!--使用AspectJ方式注解需要相应的包-->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj-version}</version>
        </dependency>
        <!--使用AspectJ方式注解需要相应的包-->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj-version}</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>



    </dependencies>
    <build>
        <finalName>ssm-simple</finalName>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>generator*.*</exclude>
                </excludes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>${mybatis-generator-version}</version>
            </plugin>
        </plugins>
    </build>

</project>

其中注释的地方就是我添加AOP相关jar包的位置,然后我在applicationContext.xml文件中配置了AOP检测注解的语句,也就是:

<aop:aspectj-autoproxy/>


配置完之后再IDEA中无报错,然后开始用tomcat部署,redeploy后结果就开始报错,错误为:

Java.lang.ClassNotFoundException:org.aspectj.lang.annotation.Around


错误描述以及解决方法请见此博客 

http://blog.csdn.net/u013147600/article/details/48132947

但问题是他的解决方法不是我的问题,因为我已经将jar包引入maven了,而且之后我尝试了更换版本号,将maven代码修改一致等等,包括maven的scope配置项修改,都不好用,这个时候我见到了另一篇博文 

http://blog.csdn.net/qqhjqs/article/details/51491516

里面一句话提醒了我

是否被打包—查看tomcat文件下对应项目中的web-INF的lib下有没有对应的jar包,然后在看看pom.xml中是怎样配置的

于是我查看了,默认IDEA是将生成的文件和war包都放在target下面的,如果不确定可以去Project-structure的artifacts查看路径,我的查看结果如下图

也就是虽然在maven里已经导入了,但是打包之后的并没有导入,于是我查看了我的代码和相关配置,又搜索了很多有关的信息,都发现自己并没有问题,这个时候google中又有一篇博客被我看到了

https://www.oschina.net/question/726953_139122

看完之后终于恍然大悟,需要在Project Structure设置中将Maven管理的jar包放到lib目录下,之后才会被打包,这个居然还要自己手动去做,耽误了这么久,图片如下

所以到此为止,基本所有在IDEA中maven可能报错NoClassDefFoundError的解决方案都被我列出来了,希望能有所帮助,除了这个坑又是一条好汉!

转自:https://blog.csdn.net/grape875499765/article/details/77104590

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xiakexiaohu/article/details/86542352

智能推荐

oracle断电断网出现的问题_heli_1005的博客-程序员宅基地

一  oracle ORA-01033 断电或者断网可能出现的1、进入CMD,执行set ORACLE_SID=fbms,确保连接到正确的SID;2、运行sqlplus "/as sysdba"      SQL>shutdown immediate      停止服务     SQL>startup                         启动服务,观察启动时有无数据文件加载

梯度、散度、旋度、拉普拉斯算子、高斯散度定理_图形跟班的博客-程序员宅基地

关于梯度、散度、旋度,笔者之前转载过一篇文章: 如何直观形象地理解梯度、散度、旋度本文(后文)内容是笔者在阅读《Fluid Simulation for Computer Graphics》的附录A.1时做的笔记。 涵盖梯度、散度、旋度、拉普拉斯算子、高斯散度定理等相关内容。Reference:[1]. Robert Bridson, Fluid Simulation for Computer

TypeError: argument 1 has unexpected type 'NoneType'(解决办法)_svg onload=alert(1)的博客-程序员宅基地

self.search.clicked.connect(self.search_information(e))在使用connect时,报TypeError: argument 1 has unexpected type 'NoneType'错误,解决办法:self.search.clicked.connect(lambda:self.search_information(e))我个人理...

java为实体类的成员变量设置默认值(mybatis为前台传的分页信息设置默认值)_怎么给分页默认值_Duktig丶的博客-程序员宅基地

java为实体类的成员变量设置默认值问题背景最近在使用mybatis写分页的时候,封装了一个PageVO用来接收前台传来的分页信息,但是这样的话,每次都需要传递分页的信息比较麻烦,就想着是否可以为分页信息设置默认值,比如默认当前页是0,每页显示20条数据。PageVOimport lombok.Data;@Datapublic class PageVO { /** 当前页 */ private Integer currentPage; /** 当前页显示数据的条数

Mybatis知识点及异常Consider defining a bean of type ‘xxx.XXXDao‘ in your configuration_suoyue_zhan的博客-程序员宅基地

Mybatis修改SQL语句的返回值:一次只修改一条语句 成功返回 1;一次修改两条及以上语句 成功返回 -1。异常:Consider defining a bean of type 'xxx.XXXDao' in your configuration

来!带你们初次体验一下ElasticAPM_程序员阿轩的博客-程序员宅基地

前言本文从最根本的可观察性出发,引出实现这种思想的APM(Application Performance Management)框架,通过对APM的核心组件和数据模型的理解,可以加深对ElasticAPM的理解。最后通过实战演练ElasticAPM,来实现应用的性能追踪。可观察性“可观察性”不是供应商能够在系统之外单独交付的功能,而是您在构建系统时植根于其中的一个属性,就像易用性、高可用性和稳定性一样。设计和构建“可观察”系统的目标在于,确保当它在生产中运行时,负责操作它的人员能够检测到不良行

随便推点

微服务架构下在zuul网关中如何获取用户信息并认证?_网关后面的应用怎样拿到用户信息_心与口不同的博客-程序员宅基地

微服务架构下如何获取用户信息并认证?在传统的单体项目中,我们对用户的认证通常就在项目里面,当拆分成微服务之后,一个业务操作会涉及多个服务。那么怎么对用户做认证?服务中又是如何获取用户信息的?这些操作都可以在 API 网关中实现。动态管理不需要拦截的 API 请求并不是所有的 API 都需要认证,比如登录接口。我们需要一个能够动态添加 API 白名单的功能,凡是在这个白名单当中的,我们就不做认证。这个配置信息需要能够实时生效,这就用上了我们的配置管理 Apollo。在 API 网关中创建一个 Apol

React-3.2 函数式组件、todoList(hooks版本)实战_CSDN_GMC的博客-程序员宅基地

React-3之函数式组件5. 函数式组件6. React hooks6.1 React Hooks 优势6.2 常用 hook6.2.1 useState6.2.2 useEffect6.2.3 useRef6.3 Hook 使用规则7. 练习 实战 - 完整todoList (hooks版本)7.1 文件app.js7.2 文件index.js7.3 文件list.js7.4 文件opt.js下节课内容练习5. 函数式组件函数式组件中,没有 state 和 生命周期,所以又被称为 无状态组件,在早期

docker-compose报错 、apt-get update 报错_qq_40051569的博客-程序员宅基地

之前很懒,加上工作忙,最近每天晚上都会更新今天安装docker-compose 和docker 报了很多错,真的是绞尽脑汁来个链接,Ubuntu安装docker时出现 依赖: containerd.io (>= 1.2.2-3) 但是它将不会被安装 错误这个连接,很棒,为了防止作者删除,copy一份作者实测,还是第二个比较彻底,我自己就是阿里源,但是不咋好用解决办法1(推荐大家使用解决办法2):查看自己能安装的版本apt-cache madison docker-ce安装指定版本=后面

centos7下Mercurial (hg)3.9.2版的安装配置及在sts使用mercurial插件clone,pull,commit,push_bizlife的博客-程序员宅基地

Mercurial 已经在centos7的安装源里存在,Mercurial是一种轻量级分布式版本控制系统,采用Python语言实现,易于学习和使用,扩展性强,其是基于GNU General Public License(GPL)授权的开源项目。mercurial 需要依赖python 2.6以上的版本,查检python版本python是2.7.5 版本没有问题 使用

IT界最短的笑话:上中台!_it业最短的笑话_天秤座的架构师的博客-程序员宅基地

01给大家讲一个IT界最短的笑话:上中台!记得罗永浩说过,期初他从英语老师跨界到IT界做手机,许多人不看好,就纷纷调侃他,比如:说一个最短的IT界的笑话——罗永浩。到了2020年,这句话应该换成:说一个最短的IT界的笑话——上中台。这两天,有一位读者给我讲了他所在的企业实施中台的故事,这是一个悲伤的故事,从中可以看到国内中台解决方案行业的乱象。20...

DOS 批处理获取文件大小_dos获取文件大小_tiberx的博客-程序员宅基地

最近研究了几天,终于写了出来.特别分享[email protected] off&setlocal enabledelayedexpansionset "fn=E:\data\345.mdb"set /a "k=0"for /f "skip=4 delims=" %%t in ('dir /-c %fn%') do ( set str=%%t set /a "k=k+1" if

推荐文章

热门文章

相关标签