0

I have an external.jar in my maven project running with IntelliJ. My class1 cannot resolve my external.jar until I remove it out from package1. Could you please suggest me a best practice in order to solve such a problem by keeping the folder structure as below.

mvn -v : Apache Maven 3.6.0, Java version: 1.8.0_212
Folder Structure:
-src
--test

---java
----package1
-----class1
----package2

---resources
----external.jar

-target
-External Libraries
Hasitha Jayawardana
  • 2,152
  • 3
  • 14
  • 32
serkmen
  • 11

2 Answers2

1

You keep all your external jars under lib folder. Refer below link

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies

LEVEL
  • 106
  • 9
  • This link describes `lib` folder _under Java home directory_, not in your project. – Alexey Romanov Jul 01 '19 at 11:44
  • Yes, you are right. Please use "lib/rt.jar" in place of "${java.home}/lib/rt.jar. " so It takes from your project folder where your pom.xml exists. – LEVEL Jul 01 '19 at 11:50
0

Steps for adding external jars in IntelliJ IDEA as follows.

  1. Click File from the toolbar
  2. Project Structure (CTRL + SHIFT + ALT + S on Windows/Linux, + ; on Mac OS X)
  3. Select Modules on the left panel
  4. Dependencies tab
  5. + → JARs or directories
  6. Select a library you want to add and click Add Selected at the bottom of the dialog

Please refer this official document from IntelliJ.

Hasitha Jayawardana
  • 2,152
  • 3
  • 14
  • 32
  • JAR is already included with this way and for that reason, there is no issue when sourcing class is not placed under a package. My problem occurs when I put my class into a package and try to use my jar. – serkmen Jul 01 '19 at 12:24
  • What error you are getting? When you move the class to that package did you refactor copied? – Hasitha Jayawardana Jul 02 '19 at 03:24