How to import external package in my project?

Discussion in 'Plugin Development' started by Hohohooo, Apr 25, 2015.

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

    Hohohooo

    I tried importing an external package in my project. And There's no problems on eclipse. Finally, I compiled my plugin with the external package, But it has occurred an error in the server console. The exception is:
    Code:
    java.lang.NoClassDefFoundError
    So, it has occurred an error because it can't find the class of the external package. What shall I do? How to import an external package right?
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
     
  2. Have you enabled that eclipse puts the package inside your jar when exporting?
     
  3. Offline

    Hohohooo

    Yes, I've put the jar in folder \lib, and my plugin still can't find it.
     
  4. Offline

    mythbusterma

    @Hohohooo

    I'm willing to bet it isn't actually being exported?
     
  5. Offline

    Hohohooo

    I really exported the externl package...Look at these images:
    [​IMG]
    [​IMG]
    It doesn't work.
     
  6. I can't see the images
     
  7. Offline

    mythbusterma

    @Hohohooo

    I don't think it would resolve it if it's in the "lib" directory, although I can't really tell how your project is set up, I can't read Chinese.
     
  8. Offline

    Hohohooo

    Well, Where shall I put the jar file? How to make it resolve the package?
     
  9. Offline

    mythbusterma

    @Hohohooo

    I believe to make it find it in the /libs/ directory, you would have to add an entry to the manifest file. It may work if you put it in the root directory of the jarfile.
     
  10. Offline

    Hohohooo

    By the way, what's the filename of the manifest file?Is it manifest.mf?
     
  11. Offline

    mythbusterma

  12. Offline

    Hohohooo

    Well, I can't use Google for putting these images on its server because Google was banned by GFW in China. You can refresh the page again:)

    I have put it in libs folder and I have created manifest.mf in root directory of the jarfile and the META-INF directory. But it still can't find the external package..........The content of the manifest.mf is:
    Code:
    Manifest-Version: 1.0
    
    Class-Path: libs/luajava-1.1.jar
    What shall I do? QAQ...

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 26, 2015
  13. Alright these are the steps you should take for adding a library or a plugin to your plugin.
    1. go into the properties of your project. Go to Java Build Path and to the tab Libraries.
    2. Click on the Add JARs... button on the right. And select your jar.
    3. Make your code (I think you already have done this.)
    4. Right click your project in the Package Explorer and click Export...
    5. Select JAR file under the folder Java in the window that should pop up. And hit Next >
    6. Select the location that you want the jar to save to, at JAR file:
    7. Hit Finish. This will generate the jar (Make sure that you have reloaded your project before exporting if you have changed any files outside eclipde, else it will give errors, and you need to reload and export again (but the file will already be created but not usable).
    8. Open the generated jar with a zip program for example 7zip or Winrar.
    9. Also open the library's jar with the zip program.
    10. Copy the content of the library's content to your plugin jar.
    11. Put the plugin jar into your server and test it.

    If the library you use is actually a plugin don't do part 8-10. Instead add the softdepend with the name of the plugin (not filename) (http://wiki.bukkit.org/Plugin_YAML) to your plugin.yml before exporting, and add the library plugin also to your server.
     
  14. Offline

    Hohohooo

    Yeah, it can find the class but an error occurred:
    I tried putting the source-code of the external package in my project, And the error is the same as the following error:
    Code:
    java.lang.UnsatisfiedLinkError: no luajava-1.1 in java.library.path
            at java.lang.ClassLoader.loadLibrary(Unknown Source)
            at java.lang.Runtime.loadLibrary0(Unknown Source)
            at java.lang.System.loadLibrary(Unknown Source)
            at org.keplerproject.luajava.LuaState.<clinit>(LuaState.java:92)
            at org.keplerproject.luajava.LuaStateFactory.newLuaState(LuaStateFactory
    .java:59)
            at com.desecity.mcscripthost.PluginMain.onEnable(PluginMain.java:24)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:457)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.jav
    a:284)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.
    java:266)
            at net.minecraft.server.v1_6_R3.MinecraftServer.l(MinecraftServer.java:3
    15)
            at net.minecraft.server.v1_6_R3.MinecraftServer.f(MinecraftServer.java:2
    92)
            at net.minecraft.server.v1_6_R3.MinecraftServer.a(MinecraftServer.java:2
    52)
            at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.jav
    a:152)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :393)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    I think it may registered the library in source-code, and it doesn't work when it's no longer a library. The error was occurred at:
    Code:
      private final static String LUAJAVA_LIB = "luajava-1.1";
    
      protected LuaState(int stateId)
      {
        luaState = _open();  //it occurred error here
        luajava_open(luaState, stateId);
        this.stateId = stateId;
      }
    So how to make the plugin find it as a library?
     
  15. Apparently your using system.loadLibrary to load it as a dynamic library. If you want to load it that way, you need to add the library jar to the folder that the system checks, and I have the feeling that it's either in the same folder as your plugin jar or the same folder as the server jar.
    The method I gave was for having the library loaded automatically by bucket or by adding the code to your jar, this way you can't use the system.loadLibrary().
     
  16. Offline

    Gater12

Thread Status:
Not open for further replies.

Share This Page