4

Alright, this is driving me nuts... I am working on a Maven project and I have 3rd Party JAR dependencies that are giving me compilation errors on IntelliJ but not in STS.

My simplified project structure is like this:

FERPAPortlet
-src
--main
---java
----edu.sandiego.parent
-----FERPAPortlet
---resources
---webapp
----META-INF
----WEB-INF
-----jsp
-----lib <----- 3rd Party JARS are here
-----liferay-display.xml
-----liferay-plugin-package.xml
-----liferay-portlet.xml
-----portlet.xml
-----web.xml
--test
-pom.xml

In SpringSource Tool Suite, if I run compile/package, everything runs fine! In fact, if I run it first in STS and then reopen with IntelliJ, the issue is solved. Nonetheless, I prefer IntelliJ over STS...

A sample error I get would be something like this when I run maven compile:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] C:\Users\rico.r-10\Documents\GitHub\github.sandiego.edu\FERPAPortlet\src\main\java\edu\sandiego\parent\FERPAPortlet.java:[3,35] error: package com.sghe.luminis.core.spring does not exist

However, when I navigate to that line, IntelliJ does not highlight it red as an error and I can actually Ctrl+click and IntelliJ will navigate to the library.

I already added the libraries via Project Structure > Project Settings > Modules > MyModule > Dependencies tab.

What is STS doing that I'm missing in IntelliJ?

EDIT: Got it working! This is what I did. I deleted the lib folder with the 3rd Party Jars. I then manually added those Jar files through the command line, like so:

mvn install:install-file "-Dfile=C:\luminis5libs\luminis-dal.jar" "-DgroupId=com.sghe.luminis" "-DartifactId=luminis-dal" "-Dversion=1.6.0" "-Dpackaging=jar"

Finally, I modified the POM to include those dependencies, like so:

<dependency>
            <groupId>com.sghe.luminis</groupId>
            <artifactId>luminis-dal</artifactId>
            <version>1.6.0</version>
        </dependency>
RommelTJ
  • 701
  • 1
  • 7
  • 20
  • You shouldn't have a lib directory. With maven, all the jars come from your local repository, and are copied into the lib directory under the target (build) directory. Check your maven dependencies, and delete lib and everything under it. Your errors are because intellij doesn't see the jars in your defined path. STS is based on eclipse, which lets you get away with any shoddy old process you want -- Intellij is more professional and, on maven projects, demands portable projects. – Software Engineer Apr 30 '14 at 19:34
  • @EngineerDollery, Thanks! I will give it a shot. I'm over-extending your help, but can you point me to documents or links that define good processes? I will have to argue with my coworker about best practices... – RommelTJ Apr 30 '14 at 19:56
  • In this case, the practice I referred to is providing a complete list of your jars/wars dependencies, so that someone deploying your application can make decisions on how to satisfy those dependencies. For example, if one the libraries in your web-inf/lib directory was huge, and your client wanted to deploy many web-apps that use it, they may choose to have the web-container provide that library, so that there is only one copy of it. If they don't know that you're using it, then they can't provide it. Worse, if they don't know you're using it, and they provide their own, slightly different – Software Engineer Apr 30 '14 at 20:20
  • [cont] slightly different version, then you could end up with subtle errors in your application. – Software Engineer Apr 30 '14 at 20:20
  • Also, we tend to have suites of web-apps, not just one, and they all tend to depend on the same libraries. If these are all referenced in a master pom, then it's relatively simple to update all the web-apps to use a new version of a library at the same time. Sometimes, this is highly desirable, sometimes less so, but maven gives us the option. Embedding the libs in the project severely limits our ability to do this. It even limits our ability to know that a webapp even uses a specific version of a lib. – Software Engineer Apr 30 '14 at 20:22
  • This is all documented on the maven website, and the associated sonatype maven book (free): http://www.sonatype.com/resources/books/maven-the-complete-reference – Software Engineer Apr 30 '14 at 20:23
  • @EngineerDollery Success! Just wanted to say thank you very much for your help. Not only did I get past the error, but the package went from ~9MB to ~6MB after I went through all the dependencies and manually vetted them into the POM. I learned a lot in the process. – RommelTJ Apr 30 '14 at 22:08
  • @EngineerDollery How do I flag you as the right answer? I'm going to edit my post with what I did and I want to give you credit for your help. – RommelTJ Apr 30 '14 at 22:11
  • You're welcome. I've put my response in as an answer, you can tick it and vote it up, if you want. – Software Engineer May 01 '14 at 13:14

2 Answers2

2

You shouldn't have a lib directory. With maven, all the jars come from your local repository, and are copied into the lib directory under the target (build) directory. Check your maven dependencies, and delete lib and everything under it. Your errors are because intellij doesn't see the jars in your defined path.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
0

Click on Maven Projects at the right border of intellij, after click on the 'Reimport all Maven projects' (the blue circular arrow)

Chaya
  • 76
  • 4