Adding Other External Jars [Eclipse]

Discussion in 'Plugin Development' started by RjSowden, Mar 20, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    RjSowden

    I'm trying to add the javamail API to my plugin, but i'm stuck. I've added in to the "lib" folder, added it to the build path and added "Class-Path: ../lib/mail.jar" to the class path. But nothing is happening. I constantly get errors from bukkit saying it cant find the external jar. I've not added any refrence to mail.jar (the javamail API) to plugin.yml, should I? Have I missed out something? I've opened the exported plugin jar file in 7zip and mail.jar IS there in /lib, and both the Manifest file in META-INF and in the root have "Class-Path: ../lib/mail.jar" in them. What Am I doing wrong?

    Please help! Thanks!
     
  2. Offline

    ZeusAllMighty11

    So you went through the project preferences and added the External .Jar file?
     
  3. Offline

    RjSowden

    right clicked lib folder, clicked import, imported jar file into lib folder. Right clicked mail.jar, clicked add to build path, jar was added to "referenced libraries". That was it for the adding stage
     
  4. Offline

    ZeusAllMighty11

    Did you check to make sure the jar file is actually there? :p
     
  5. Offline

    RjSowden

    Yep. Its in the plugins exported jar file inside the lib folder.
     
  6. Offline

    Karl Marx

    Adding the lib to your class path & exporting it with your jar is intended for running the jar as a stand-alone application. Bukkit does not directly run your jar, but dynamically loads the classes itself (hence the plugin.yml file, and lack of a "main".)

    You do need to import the mail jar into your project for compilation purposes, but you do not need to add it to your classpath. I don't know anything about the library itself, but most of the Bukkit libraries I've used are independant plugins that you just have to install like any other plugin.
     
  7. Offline

    RjSowden

    Javamail isn't a bukkit library, it was made for the entire Java language. I've tried leaving the manifest file alone so the mail.jar isn't in the class path, but that hasn't done anything either.
     
  8. Offline

    Karl Marx

    I see. Since bukkit does not use your jar's classpath, though, your only options there are to directly embed the library's classes into your jar, install javamail as a system library (and have your users do the same,) or else dynamically load the classes yourself.

    I'd recommend the first option, but it all depends on your particular needs.
     
  9. Offline

    flungo

    Not sure if you got this sorted but here is what I would do. Create a folder on your computer that you will store you libraries (e.g. Bukkit (obviously), Vault, WorldEdit, any other plugins that have an API you want to use and this mail.jar library you want to use).

    In eclipse, right click your project. Hover over "Build Path", select "Add External Jars" navigate to the folder on your computer and add the JARs required for your project. This wont actually put any of these files in your project at the time of exporting but allows Esclipse to understand 99.99% of the stuff you will be writing for a Bukkit plugin and allow it to understand any API's from the Javamail library.

    You then have to do what @karl-marx has said which is get all your users to have the file in their Java Library. I am not 100% certain but I think the user can put a lib folder parallel to the craftbukkit.jar file where bukkit will try and load libraries. Test it out. If that doesn't work then they have to put in in their Java install!
     
  10. Offline

    RjSowden

    I'm going to try dynamically loading the classes myself, because I need the plugin to be simple to use. Thanks everyone anyways!
     
Thread Status:
Not open for further replies.

Share This Page