Is there a permanent fix for Eclipse Deployment Assembly losing the Maven Dependencies?

前端 未结 3 1094
失恋的感觉
失恋的感觉 2021-02-08 12:15

I had a problem similar to this (java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener), the difference in my case is that the common fix (addi

3条回答
  •  [愿得一人]
    2021-02-08 12:53

    This kind of problem is solved by:

    • getting the latest version of the Eclipse IDE for Java EE Developers. As of today, this is Eclipse Mars 4.5. Be sure to select the 64 bit version (if your computer is 64 bit) and to install the latest 64 bit JDK (as of today, this is jdk-8u60).
    • correctly setting up the JREs in Eclipse by selecting the installed JDK in the Preferences ("Java > Installed JREs").
    • having up-to-date m2e and m2e-wtp plugins. This is done by going to "Help > Install New Software...", setting this URL for m2e and this URL for m2e-wtp and then installing every proposed software (don't forget to reboot Eclipse after that).
    • correctly setting up the server in Eclipse: in the "Servers" view, right-click and select "New > Server" and then follow the steps for your specific server; in the end, you will need to add your war through the "Add and Remove..." screen.
    • cleaning the project in Eclipse by selecting it and going to "Project > Clean".
    • updating the Maven project by right-clicking the project in Eclipse and going to "Maven > Update Project...".
    • cleaning the server by right-clicking the server and selecting "Clean" (this depends on your server but there's usually a "Clean" option).

    I recommend you do all these steps on a fresh Eclipse install to avoid general caching issues.

    As a side note, there are several problems with your POM as-is:

    • javax.servlet:javax.servlet-api dependency needs to have the provided scope since this dependency is always provided by the web-server at run-time.
    • javax.servlet:jstl dependency probably doesn't need to have the compile scope and runtime will suffice.
    • You are declaring a lot of Spring dependencies when you don't need to: they will still be included because they already are transitive dependencies of other artifacts. As such, you can remove the declaration of spring-aop, spring-beans, spring-context, spring-expression, spring-tx and spring-web.
    • Your testing dependencies are missing the test scope (testng, mockito-all...)
    • true is unnecessary in your maven-compiler-plugin declaration as this is the default.

    Final POM would be:

    
    
        4.0.0
        ctc.web.proyect
        front.web
        war
        0.2.5
        front.web
    
        
            UTF-8
            3.1.0
            1.2
            4.1.5.RELEASE
            2.1.4.RELEASE
            2.5.3
            5.1.30
            0.9.1.2
            1.1.1
            1.7.7
            6.8.8
            3.3.2
            1.9.5
            2.2.2
            18.0
            1.4.1
            1.4.7
            1.8.6
            5.3.0
        
    
        
    
            
            
                javax.servlet
                jstl
                ${javax.servlet.jstl}
                runtime
            
            
                javax.servlet
                javax.servlet-api
                ${javax.servlet.version}
                provided
            
    
            
            
                org.springframework
                spring-core
                ${org.springframework.version}
                
                    
                        commons-logging
                        commons-logging
                    
                
            
            
                org.springframework
                spring-context-support
                ${org.springframework.version}
            
            
                org.thymeleaf
                thymeleaf-spring4
                ${thymeleaf.version}
            
            
            
                org.springframework
                spring-jdbc
                ${org.springframework.version}
            
            
                org.springframework
                spring-oxm
                ${org.springframework.version}
            
            
                org.springframework
                spring-webmvc
                ${org.springframework.version}
            
            
                org.springframework
                spring-test
                ${org.springframework.version}
                test
            
            
            
                com.fasterxml.jackson.core
                jackson-databind
                ${jackson.version}
            
            
            
                mysql
                mysql-connector-java
                ${mysql.version}
            
            
            
                ch.qos.logback
                logback-classic
                ${logback.version}
            
            
                org.slf4j
                jcl-over-slf4j
                ${slf4j.version}
            
            
                org.slf4j
                slf4j-api
                ${slf4j.version}
            
            
                org.slf4j
                slf4j-log4j12
                ${slf4j.version}
            
    
            
                c3p0
                c3p0
                ${c3p0.version}
            
    
            
            
                org.apache.commons
                commons-lang3
                ${commons-lang3.version}
            
            
                commons-validator
                commons-validator
                ${commons-validator.version}
                
                    
                        commons-logging
                        commons-logging
                    
                
            
            
            
                com.google.guava
                guava
                ${guava.version}
            
    
            
            
                org.testng
                testng
                ${testng.version}
                test
            
            
                org.mockito
                mockito-all
                ${mockito.version}
                test
            
            
                cglib
                cglib
                ${cglib.version}
            
            
                javax.mail
                mail
                ${javax.mail.version}
            
            
                org.aspectj
                aspectjrt
                ${org.aspectj.version}
            
            
                org.aspectj
                aspectjweaver
                ${org.aspectj.version}
            
            
                org.apache.lucene
                lucene-analyzers-common
                ${apache.lucene.version}
            
            
                org.apache.lucene
                lucene-queryparser
                ${apache.lucene.version}
            
            
            
            
            
            
            
                com.google.api-client
                google-api-client
                1.20.0
                
                    
                        commons-logging
                        commons-logging
                    
                
            
        
    
        
            ROOT
            
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    2.3.2
                    
                        1.8
                        1.8
                    
                
            
        
    
    

    The other consideration you might want to fix is that your groupId and artifactId do not follow Maven conventions: prefer using - as separator instead of ..

提交回复
热议问题