1

I have a .java file that makes use of JSON library, it imports the library's package:

enter image description here

However the package isn't recognised, so I tried to add the library to my project:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

But it didn't work:

enter image description here

My library is located inside Root/libs/LibraryFolder1/LibraryFolder2/.java files and .classe files and .jar file

I tried importing both .jar and .java and library as a whole (by clicking on the root folder). Neither worked.

EDIT: I've also tried running a command:

mvn install:install-file -Dfile=C:\xampp\tomcat\webapps\Root\libs\LibraryFolder1\LibraryFolder2\Craps.jar -DgroupId=org.json -DartifactId=json -Dpackaging=jar -Dversion=20150912 -DgeneratePom=true

which gives a BUILD SUCCESS result, but doesn't seem to change anything.

parsecer
  • 4,758
  • 13
  • 71
  • 140
  • `Craps.jar` - I'm glad to see I'm not the only one giving descriptive names. – skandigraun Sep 23 '18 at 19:01
  • @skandigraun ))) Descibes my feelings quite well. I'm not happy with Idea... – parsecer Sep 23 '18 at 19:04
  • Did you try to install the lib with maven, like [this](https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project)? I remember I had success in the past with something like the 2nd answer. – skandigraun Sep 23 '18 at 19:05
  • @skandigraun See edit. Tried running a maven command, didn't seem to work. Though I've never run maven commands from terminal before, used only GUI. – parsecer Sep 23 '18 at 19:33
  • After that you can add it to your pom.xml file - it is already in your local repo/cache, at least in theory. Try adding `org.jsonjson20150912` to your pom.xml. – skandigraun Sep 23 '18 at 19:37

1 Answers1

1

Since you are using Maven as your dependency (aka libraries) management, you cannot add it in your ide and expect it to work. It will be overriten to what you have in your POM file when you synchronize the project. Moreover, if you would make this to work from IDE, compilation would fail on CLI so bye bye every auto build tools.

To make this work, you mas add your local JAR to your local Maven repository and include it trough POM file.

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

After you install your Craps.jar as Maven artifact, include it in dependencies section in POM file.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99