Results 1 to 6 of 6

Thread: Can you edit a jar archive (compiled) without the original project

  1. #1
    Join Date
    Jun 2009
    Posts
    59

    Can you edit a jar archive (compiled) without the original project

    I developed a multi-agents where the developer did need the JAR of this platform to build applications (MAS: Multi-Agent System). I'm toning some examples to test and validate the platform. In one example, I built a class that inherits AgentVendor class AgentAtomic (located in the JAR). I instantiates and it works but when using methods that manipulate the type AgentAtomic in the class of the JAR and I do the cast to AgentVendor; an exception occurs. I was able to resolve this exception so that the class AgentVendor be found in the jar of the platform. But I do not understand why the class AgentVendor must be in the JAR to the platform? And therefore I wonder if we can modify a jar archive (compiled) without the original project? Because the developer will not have the source code of the application and will work with the JAR. AND is that there is another way to solve this problem without adding this class to JAR.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Can you edit a jar archive (compiled) without the original project

    Your question is somewhat less descriptive as well as confusing to me! Can you clear my points like what do you mean by "can change a jar archive"; can you tell us what is the exception that you are getting?

  3. #3
    Join Date
    Jun 2009
    Posts
    59

    Re: Can you edit a jar archive (compiled) without the original project

    Hello, so class that inherits AgentVendor class AgentAtomic must be in the jar for example working (I do not understand why!) So is there a way to add classes .java or\and .class in the JAR? without needing the source code of the application to create a new JAR containing this class. For the user of this platform has only the JAR.

    The exception is raised when I type casting AgentAtomic to AgentVendor; because I getAgent method () which returns AgentAtomic when I cast value AgentVendor exception rises. This problem arises AgentVendor if the class is not found in JAR. When I inserted the class AgentVendor in the source code and recreate the JAR and all works well. I DO NOT UNDERSTAND WHY?

    I re-run the example (I did not put the class AgentVendor in the Jar I placed in the project that contains the sample). The exception is java.lang.ClassCastException: AgentVendor can not be cast to AgentVendor. Can anyone explain ?

  4. #4
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Can you edit a jar archive (compiled) without the original project

    The exception is java.lang.ClassCastException: AgentVendor can not be cast to AgentVendor.
    You have twice the class AgentVendor present in various classloaders. It is the cause of your error. It is this class in the classloader ream restriction when you do "(AgentVendor) xxxx" and the class returned by the method that you called. As these classes are loaded by different classloader, they are different. Viewing already why this class is duplicated in your classloader, cases are extremely rare and often result from an application that tinkering around with classloaders.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Can you edit a jar archive (compiled) without the original project

    Normally use a class of third-lib poses no particular concern. Many Java libraries are not open source and can handle classes jar corresponding to the third party libraries without concern (assuming that classes are declared public).

    I personally look instead for the sake of setting projects in your environment.

    The exception "java.lang.ClassCastException: AgentVendor can not be cast to AgentVendor" could be caused by the fact that the class AgentVendor exists twice in your project where you encounter the problem: the same name but each refers to a version of this class in a different jar.

    For example, if your project includes the source code AgentVendor first, but AgentVendor is also included through the JAR added to the classpath of your project during its execution: the same name but they are two Java completely separate classes, it behaves as if we had two classes with two different names.

  6. #6
    Join Date
    Jun 2009
    Posts
    59

    Re: Can you edit a jar archive (compiled) without the original project

    Yeah, you're right I use the classloader to instantiate classes dynamically. In fact AgentVendor class is instantiated dynamically and the user only have to enter the name and path of the class and then instantiating a sales agent that adds skills. These skills are also classes that will instantiate. Please, can you explain where the problem exactly? And how can we solve this problem.

    In our application we have not used classloader, but URLLoader to load the address of the class. And from what I read on the ClassLoader, they exist in the JVM to load a class when asked to run. So how to always use the same ClassLoader?

Similar Threads

  1. Tropico 4 features Compiled list
    By Loveyboo in forum Video Games
    Replies: 6
    Last Post: 24-08-2011, 11:57 PM
  2. C Program typed in Notepad can be Compiled using Turbo C
    By Kusagra in forum Software Development
    Replies: 8
    Last Post: 23-03-2011, 11:37 PM
  3. Compiled files do not run with Snow Leopard with i7
    By Bearer in forum Software Development
    Replies: 6
    Last Post: 25-09-2010, 12:22 PM
  4. Replies: 4
    Last Post: 23-10-2009, 08:26 AM
  5. cannot run c compiled programs
    By Unix'EM in forum Operating Systems
    Replies: 3
    Last Post: 22-08-2009, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,719,040,605.12436 seconds with 16 queries