简体   繁体   中英

import org.apache.commons cannot be resolved when migrating to Java 8

We are upgrading our maven project to java 8 along with compatible tomcat. The code is now being compiled with following errors:-

    Caused by: java.lang.Error: Unresolved compilation problems:
            The import org.apache.commons cannot be resolved
            The import org.apache.commons cannot be resolved
            The import org.apache.commons cannot be resolved

However it was working fine in Java 6 and Tomcat 7. We have checked that all the jars are included in WEB-INF/lib . It seems none of the apache-commons jar are getting recognized (not sure whats the correct term).

Just to check I moved apache-commons jars to tomcat/lib (never a solution obviously), but still same error.

Here's the Java and tomcat we are using :-

OpenJDK Runtime Environment (build 1.8.0_161-b14)

apache-tomcat-8.5.32

You need to update your project's POM.xml file to include dependencies for the Apache Commons libraries that you are using. If you do it correctly, the JARs will be downloaded from Maven Central into your ~/.m2 local repo, and added by Maven to the compile time build path. Then when Maven creates the WAR file for your project, it will include the JARs in the appropriate place in the WAR file ... ready for deployment to your Tomcat.

I recommend that you do some reading on Maven, the POM file and how Maven handles dependencies. The official "Maven Getting Started Guide" would be a good place to start.

It is unclear how you managed to get your project to build previously under Maven without the proper dependencies. I am guessing that you weren't using Maven before. Or maybe someone had been building by hand using IDE and ignoring Maven and the POM file entirely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM