Eclipse and Javax

Discussion in 'Plugin Development' started by TMAsantos, Jul 14, 2012.

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



    I'm trying to import javax.* folder to my bukkit plugin.
    I cant just add external jars, because when I run my server, it will not find the packages.
    I've tried to copy the folders to my plugin src folder, but it does not work, it does not find all the .class files.

    What sould I do?


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 27, 2016
  2. Ehh... you mean fizically add the javax folder in your plugin ? Why ? It's already in the JDK (at least 1.6+), just use "import javax.*;" because it works just fine.
  3. Offline

    Sagacious_Zed Bukkit Docs

    Most platforms don't have all of javax, especially the newer parts of javax.
  4. Offline


    Digi mail.jar from Javax isn't.

    I just want to import the folders/functions to my project, but i'm always receiving this error:
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: javax/mail/MessagingException
    Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
  5. Offline


    Has anyone figured this out? To help here is the method I am using to call on the JavaMail classes
    1. publicvoid email() {
    2. Properties props = new Properties();
    3. props.put("", "");
    4. props.put("mail.smtp.socketFactory.port", "465");
    5. props.put("mail.smtp.socketFactory.class",
    6. "");
    7. props.put("mail.smtp.auth", "true");
    8. props.put("mail.smtp.port", "465");
    10. Session session = Session.getInstance(props,
    11. new javax.mail.Authenticator() {
    12. protected PasswordAuthentication getPasswordAuthentication() {
    13. return new PasswordAuthentication("zeeveener","(REDACTED)");
    14. }
    15. });
    17. try {
    19. Message message = new MimeMessage(session);
    20. message.setFrom(new InternetAddress("[EMAIL][email protected][/EMAIL]"));
    21. message.setRecipients(Message.RecipientType.TO,
    22. InternetAddress.parse("(REDACTED)"));
    23. message.setSubject("Testing Subject");
    24. message.setText("Dear Mail Crawler," +
    25. "\n\n No spam to my email, please!");
    27. Transport.send(message);
    29. System.out.println("Done");
    31. } catch (MessagingException e) {
    32. throw new RuntimeException(e);
    33. }
    34. }

    This is the error that I am getting:
    19:48:18 [SEVERE] Could not load 'plugins/ZResponder.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: javax/mail/MessagingException
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(
        at org.bukkit.craftbukkit.CraftServer.<init>(
        at net.minecraft.server.ServerConfigurationManager.<init>(
        at net.minecraft.server.MinecraftServer.init(
    Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(
        ... 8 more
    Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
        at Method)
        at java.lang.ClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(
        ... 11 more
    EDIT: I have added both mail.jar and activation.jar to the Build Path of this plugin and am simply calling upon the method from within onEnable() just to make sure it works. However, it wont even load...
    I have been looking online for an answer for a week and nothing has come of it... I really really need help before I start to go insane.
    EDIT2: I figured out how to run it on my test server on my personal machine... However, i had to place it in a very specific place. Where do I put it on a different machine running a different OS?
  6. Offline

    Sagacious_Zed Bukkit Docs

    You must also make sure all classes you are using are on the classpath of the jvm you are using. Personally, the best way is to shade it into your plugins jar, but that requires the use of maven.
  7. Offline


    I don't use eclipse, but I believe it can export a 'jar with depends' or similar.
  8. Offline


    Does using Maven require anything from the Server Admin's side of the table? Or can I just compile the plugin and it will work properly.

    If the option is there, I don't know where to find it.
  9. Offline

    Sagacious_Zed Bukkit Docs

    Maven is a build tool, so you just need to modify your project. As for the export jar with depends, i have not found it to be all that reliable.
  10. Offline


    Ok. I think I may have figured it out finally.
    What I did:
    1. Right click the project and import mail.jar and activation.jar into a lib source folder beside my src folder.(The required libraries)
    2. Right click both those files and Build Path -> Add to Build Path
    3. I then created another normal folder named "META-INF"
    4. During export, I created a new MANIFEST.MF inside that folder.
    5. I Then proceeded to edit that manifest inside Eclipse to include: Class-Path: lib/activation.jar lib/mail.jar
    6. I then created a folder named "lib" inside the (Server)/plugins folder and placed the required jars in there.
    7. After exporting the plugin again with the new manifest, it all seems to work fine.

    All I need to do now is test it on the larger server that I am running, but that wont happen until i figure out why it is crashed all of a sudden lol. Oh well, at least im not getting a broken error anymore and it actually sends the email.
    Wituz likes this.
  11. Offline


    For ANT I use this to create a jar with dependencies included :
    <target name="-post-jar">
    <jar jarfile="dist/originalBuild.jar">
    <zipfileset src="${dist.jar}" excludes="META-INF/*" />
    <zipfileset src="x.jar" excludes="META-INF/*" />
    <attribute name="Main-Class" value="me.plugin.Main" />

    put it right before </project> at the end of build.xml

    On a side note, maven is better.
  12. Offline


Thread Status:
Not open for further replies.

Share This Page