0

I have an applet that needs to import another libraries. I used Apache Ant to build this applet and libraries into same jar files, but there is no way to connect classes with libraries. I got NoClassDefFoundError.

Because of that I decided to use one-jar with Ant. One-jar creates a jar files that contains libraries and classes. But classes that I wrote are in another jar inside of main jar. Directory looks like below :

  • main.jar
    • com
    • doc
    • lib
    • main
      • applets.jar
        • MyApplet.class

I need to access MyApplet class in applets.jar file but problem is that how can I import my applet class which is in second jar. It's not possible to write second attribute in applet tag.

Is there any option in one-jar to build only one jar with libraries? What should I use?

Maozturk
  • 339
  • 1
  • 5
  • 20

1 Answers1

1

It's not possible to write second attribute in applet tag.

Then it is a good thing there is no need to. The archive attribute of the applet element can list multiple Jars, which is how you should approach this.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Andrew, but applet which I want to access is inside of first jar, can I write archive like this : `archive = "main.jar, applets.jar"` – Maozturk Dec 31 '13 at 18:11
  • You can write it any way you like! But then ..what happened when you *tried it?* – Andrew Thompson Dec 31 '13 at 18:13
  • it throwed exception : `ClientAbortException: java.net.SocketException: Software caused connection abort: socket write error` Actually I didn't understand that is it possible to write jar name which is inside of main jar in `archive` attribute? – Maozturk Dec 31 '13 at 18:32
  • Any comment about my main problem? How can I add applet which is inside of second jar? – Maozturk Dec 31 '13 at 18:40
  • OK I'm a little confused. If you have both Jars listed in the `archive` attribute, it is simply a matter of adding the Fully Qualified Name of any applet in any of the Jars as the `code` attribute in order to load it in HTML. How does that *not* work for you? – Andrew Thompson Dec 31 '13 at 18:44
  • I think I can not use archive attribute for my two JARs, because they are nested, applet JAR is in main JAR. I wanna use applet class in web page. Directory of JAR is in my post. – Maozturk Dec 31 '13 at 18:56
  • *"because they are nested"* Well my point is **Don't nest them.** Just add each Jar to the `archive` attribute! Also, please refrain from using slang like 'wanna'. If someone who speaks English as a 2nd language is trying to help you, they may have to use Google translate to understand. I don't know how it handles slang, but best not test it. Also ..I detest seeing slang in technical posts. It does not put me in a mood conducive to helping. – Andrew Thompson Dec 31 '13 at 19:00
  • Using libraries seperately is more complicated for my situation, because there are a lot of libraries that applet needs to import. So I thought that better approach is using them nested as a JAR. – Maozturk Dec 31 '13 at 19:10
  • *"Using libraries seperately is more complicated for my situation.."* (Reviews thread, and comments.) And this lot seems ..simple?!? Applets are (and always have been) a complete PITA to develop, deploy and maintain. See [this blog post](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/) for my views on the matter. – Andrew Thompson Dec 31 '13 at 19:12
  • Oh, also note: For 'jar in a jar' to work requires a custom class-loader, which in turn requires a trusted applet. It *really* complicates matters. – Andrew Thompson Dec 31 '13 at 19:15
  • Oh, seems like it will be more complicated increasingly, I've spent a week to solve. Well, sorry but is there any way to build JAR from classes and libraries together? I want to build a JAR file that doesn't need anything, all dependencies should be in that JAR. Note that I can not choose technology that we use, so I must solve problem using Applet. – Maozturk Dec 31 '13 at 19:25
  • *"..is there any way to build JAR from classes and libraries together?"* Sure there is, but there are also *good reasons **not** to do that,* including violating the license of 3rd party APIs, destruction of necessary information in the manifests of those Jars.. I could go on, but I won't. ***Just do it the standard way!*** – Andrew Thompson Dec 31 '13 at 19:29