Eclipse and Javax

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

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

    TMAsantos

    Hey,

    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?
    Thanks

    anyone?

    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

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

    TMAsantos

    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

    zeeveener

    Has anyone figured this out? To help here is the method I am using to call on the JavaMail classes
    Code:java
    1. publicvoid email() {
    2. Properties props = new Properties();
    3. props.put("mail.smtp.host", "smtp.gmail.com");
    4. props.put("mail.smtp.socketFactory.port", "465");
    5. props.put("mail.smtp.socketFactory.class",
    6. "javax.net.ssl.SSLSocketFactory");
    7. props.put("mail.smtp.auth", "true");
    8. props.put("mail.smtp.port", "465");
    9.  
    10. Session session = Session.getInstance(props,
    11. new javax.mail.Authenticator() {
    12. protected PasswordAuthentication getPasswordAuthentication() {
    13. return new PasswordAuthentication("zeeveener","(REDACTED)");
    14. }
    15. });
    16.  
    17. try {
    18.  
    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!");
    26.  
    27. Transport.send(message);
    28.  
    29. System.out.println("Done");
    30.  
    31. } catch (MessagingException e) {
    32. throw new RuntimeException(e);
    33. }
    34. }


    This is the error that I am getting:
    Code:
    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.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:151)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:214)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:190)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:55)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:158)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:424)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:140)
        ... 8 more
    Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 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

    md_5

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

    zeeveener

    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

    zeeveener

    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

    AJCStriker

    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/*" />
    <manifest>
    <attribute name="Main-Class" value="me.plugin.Main" />
    </manifest>
    </jar>
    </target>

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

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

    zeeveener

Thread Status:
Not open for further replies.

Share This Page