java.lang.NoClassDefFoundError

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.NoClassDefFoundError

Jorge
When I run this code in an agent, I don't have any problems:

RunState.getInstance()
                .getMasterContext().getAgentTypes();

but when I'm in an agent and I call someOtherObject.call() and run the same command from that other object:

RunState.getInstance()
                .getMasterContext().getAgentTypes();

I get the following error:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
        at repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
        at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
        at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
        at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
        at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
        at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
        at jzombies.Zombie$$FastClassByCGLIB$$6141f31.invoke(<generated>)
        at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
        at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
        ... 7 more
...
Caused by: java.lang.NoClassDefFoundError: repast/simphony/engine/environment/RunState
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.NoClassDefFoundError

Ozik, Jonathan
Is this other object in a separate jar? If so, how are you adding it to the Repast Simphony project?

Jonathan

> On Aug 27, 2015, at 12:01 AM, Jorge <[hidden email]> wrote:
>
> When I run this code in an agent, I don't have any problems:
>
> RunState.getInstance()
>                .getMasterContext().getAgentTypes();
>
> but when I'm in an agent and I call someOtherObject.call() and run the same
> command from that other object:
>
> RunState.getInstance()
>                .getMasterContext().getAgentTypes();
>
> I get the following error:
>
> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
> at
> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
> at
> repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
> at
> repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
> at
> repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
> at
> repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
> at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
> at
> repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
> at java.lang.Thread.run(Unknown Source)
> Caused by: java.lang.reflect.InvocationTargetException
> at jzombies.Zombie$$FastClassByCGLIB$$6141f31.invoke(<generated>)
> at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
> at
> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
> ... 7 more
> ...
> Caused by: java.lang.NoClassDefFoundError:
> repast/simphony/engine/environment/RunState
>
>
>
> --
> View this message in context: http://repast.10935.n7.nabble.com/java-lang-NoClassDefFoundError-tp11181.html
> Sent from the repast-interest mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Repast-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.NoClassDefFoundError

Jorge
It's in a separate Java project in the same Eclipse workspace.  The
Repast project has this other Java project in both its build path and
in its runtime configuration classpath.  I had problems getting third
party JARs to work without setting it up this way.

That other Java project does have its build path set up with a
dependency repast.simphony.bin_and_src.jar, as it needs some Repast
classes to compile.  Are there differences in the Repast classes in
that src jar and whatever is used when executing a regular Repast GUI
simulation?

Jorge

On Thu, Aug 27, 2015 at 2:54 PM, Ozik, Jonathan <[hidden email]> wrote:

> Is this other object in a separate jar? If so, how are you adding it to the Repast Simphony project?
>
> Jonathan
>
>> On Aug 27, 2015, at 12:01 AM, Jorge <[hidden email]> wrote:
>>
>> When I run this code in an agent, I don't have any problems:
>>
>> RunState.getInstance()
>>                .getMasterContext().getAgentTypes();
>>
>> but when I'm in an agent and I call someOtherObject.call() and run the same
>> command from that other object:
>>
>> RunState.getInstance()
>>                .getMasterContext().getAgentTypes();
>>
>> I get the following error:
>>
>> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>>       at
>> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
>>       at
>> repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
>>       at
>> repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
>>       at
>> repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
>>       at
>> repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
>>       at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
>>       at
>> repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
>>       at java.lang.Thread.run(Unknown Source)
>> Caused by: java.lang.reflect.InvocationTargetException
>>       at jzombies.Zombie$$FastClassByCGLIB$$6141f31.invoke(<generated>)
>>       at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
>>       at
>> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
>>       ... 7 more
>> ...
>> Caused by: java.lang.NoClassDefFoundError:
>> repast/simphony/engine/environment/RunState
>>
>>
>>
>> --
>> View this message in context: http://repast.10935.n7.nabble.com/java-lang-NoClassDefFoundError-tp11181.html
>> Sent from the repast-interest mailing list archive at Nabble.com.
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Repast-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/repast-interest
>

------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.NoClassDefFoundError

Ozik, Jonathan
The best way to include third party jars that your model needs is to drop them into your lib folder and just add them to your build path. You should not add them to your launch path (aka, runtime configuration classpath). Repast Simphony will load those jars with its own classloader.
The easiest way in my experience to integrate your separate Java project into your model then is to jar up the bin folder and drop it into the lib folder. This will also enable you to run the model in batch mode.

> On Aug 27, 2015, at 3:42 PM, Jorge Calderon <[hidden email]> wrote:
>
> It's in a separate Java project in the same Eclipse workspace.  The
> Repast project has this other Java project in both its build path and
> in its runtime configuration classpath.  I had problems getting third
> party JARs to work without setting it up this way.
>
> That other Java project does have its build path set up with a
> dependency repast.simphony.bin_and_src.jar, as it needs some Repast
> classes to compile.  Are there differences in the Repast classes in
> that src jar and whatever is used when executing a regular Repast GUI
> simulation?
>
> Jorge
>
> On Thu, Aug 27, 2015 at 2:54 PM, Ozik, Jonathan <[hidden email]> wrote:
>> Is this other object in a separate jar? If so, how are you adding it to the Repast Simphony project?
>>
>> Jonathan
>>
>>> On Aug 27, 2015, at 12:01 AM, Jorge <[hidden email]> wrote:
>>>
>>> When I run this code in an agent, I don't have any problems:
>>>
>>> RunState.getInstance()
>>>              .getMasterContext().getAgentTypes();
>>>
>>> but when I'm in an agent and I call someOtherObject.call() and run the same
>>> command from that other object:
>>>
>>> RunState.getInstance()
>>>              .getMasterContext().getAgentTypes();
>>>
>>> I get the following error:
>>>
>>> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>>>     at
>>> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
>>>     at
>>> repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
>>>     at
>>> repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
>>>     at
>>> repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
>>>     at
>>> repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
>>>     at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
>>>     at
>>> repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
>>>     at java.lang.Thread.run(Unknown Source)
>>> Caused by: java.lang.reflect.InvocationTargetException
>>>     at jzombies.Zombie$$FastClassByCGLIB$$6141f31.invoke(<generated>)
>>>     at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
>>>     at
>>> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
>>>     ... 7 more
>>> ...
>>> Caused by: java.lang.NoClassDefFoundError:
>>> repast/simphony/engine/environment/RunState
>>>
>>>
>>>
>>> --
>>> View this message in context: http://repast.10935.n7.nabble.com/java-lang-NoClassDefFoundError-tp11181.html
>>> Sent from the repast-interest mailing list archive at Nabble.com.
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Repast-interest mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/repast-interest
>>


------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.NoClassDefFoundError

Tatara, Eric R.
In reply to this post by Jorge
Jorge,

The Repast RunState instance doesn't exist unless a Repast simulation has been initialized, so trying to reference it from code anywhere other than inside of an initialized simulation model won't work.  Jonathan's suggestion on using the lib folder to include third party jars should work - let us know otherwise.

eric

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory

________________________________________
From: Jorge Calderon [[hidden email]]
Sent: Thursday, August 27, 2015 3:42 PM
To: Ozik, Jonathan
Cc: [hidden email]
Subject: Re: [Repast-interest] java.lang.NoClassDefFoundError

It's in a separate Java project in the same Eclipse workspace.  The
Repast project has this other Java project in both its build path and
in its runtime configuration classpath.  I had problems getting third
party JARs to work without setting it up this way.

That other Java project does have its build path set up with a
dependency repast.simphony.bin_and_src.jar, as it needs some Repast
classes to compile.  Are there differences in the Repast classes in
that src jar and whatever is used when executing a regular Repast GUI
simulation?

Jorge

On Thu, Aug 27, 2015 at 2:54 PM, Ozik, Jonathan <[hidden email]> wrote:

> Is this other object in a separate jar? If so, how are you adding it to the Repast Simphony project?
>
> Jonathan
>
>> On Aug 27, 2015, at 12:01 AM, Jorge <[hidden email]> wrote:
>>
>> When I run this code in an agent, I don't have any problems:
>>
>> RunState.getInstance()
>>                .getMasterContext().getAgentTypes();
>>
>> but when I'm in an agent and I call someOtherObject.call() and run the same
>> command from that other object:
>>
>> RunState.getInstance()
>>                .getMasterContext().getAgentTypes();
>>
>> I get the following error:
>>
>> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>>       at
>> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
>>       at
>> repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
>>       at
>> repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
>>       at
>> repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
>>       at
>> repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
>>       at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
>>       at
>> repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
>>       at java.lang.Thread.run(Unknown Source)
>> Caused by: java.lang.reflect.InvocationTargetException
>>       at jzombies.Zombie$$FastClassByCGLIB$$6141f31.invoke(<generated>)
>>       at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
>>       at
>> repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
>>       ... 7 more
>> ...
>> Caused by: java.lang.NoClassDefFoundError:
>> repast/simphony/engine/environment/RunState
>>
>>
>>
>> --
>> View this message in context: http://repast.10935.n7.nabble.com/java-lang-NoClassDefFoundError-tp11181.html
>> Sent from the repast-interest mailing list archive at Nabble.com.
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Repast-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/repast-interest
>

------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.NoClassDefFoundError

Jorge
I added the third party JARs to the lib directory, added the JAR to my build configuration, but Eclipse doesn't recognize the class when I add the import statement to an agent.  I did this on a new Repast sample project, so the scenario.xml is set up correctly with the reference to the lib directory.  Adding the libraries in the run configurations is the workaround I've been using.

To go back to the problem with RunState, since I am using a JAR as a library, and I'm calling it after the agent is initialized (I'm calling it from the agent's run method), shouldn't the RunState instance exist already?  If I call "RunState rs = RunState.getInstance()" from the agent, and then I call the object in my the JAR that itself calls RunState, then all the code runs ok.  It's only when I don't first save the instance in the Repast agent that I have problems in the code in the JAR.

When I get the classloader in my agents, I get back:
{PluginClassLoader: uid=619992292; {PluginDescriptor: uid=repast.simphony.batch@0.0.0}}

but in the other class I get back:
sun.misc.Launcher$AppClassLoader@749cd006

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.NoClassDefFoundError

Ozik, Jonathan
See my responses below.

> On Aug 29, 2015, at 12:44 AM, Jorge <[hidden email]> wrote:
>
> I added the third party JARs to the lib directory, added the JAR to my build
> configuration, but Eclipse doesn't recognize the class when I add the import
> statement to an agent.
This is strange. You went to the Java Build Path element in the project properties and added the jar from within your lib folder and Eclipse doesn’t recognize imports from it?

>  I did this on a new Repast sample project, so the
> scenario.xml is set up correctly with the reference to the lib directory.
This shouldn't have anything to do with Eclipse’s editor not recognizing the classes in the jars.

> Adding the libraries in the run configurations is the workaround I've been
> using.
This “workaround” is problematic as you show below. The wrong class loader is loading those classes.

>
> To go back to the problem with RunState, since I am using a JAR as a
> library, and I'm calling it after the agent is initialized (I'm calling it
> from the agent's run method), shouldn't the RunState instance exist already?
> If I call "RunState rs = RunState.getInstance()" from the agent, and then I
> call the object in my the JAR that itself calls RunState, then all the code
> runs ok.  It's only when I don't first save the instance in the Repast agent
> that I have problems in the code in the JAR.
>
> When I get the classloader in my agents, I get back:
> {PluginClassLoader: uid=619992292; {PluginDescriptor:
> uid=repast.simphony.batch@0.0.0}}
>
> but in the other class I get back:
> sun.misc.Launcher$AppClassLoader@749cd006
>
>
>
>
>
> --
> View this message in context: http://repast.10935.n7.nabble.com/java-lang-NoClassDefFoundError-tp11181p11187.html
> Sent from the repast-interest mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Repast-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/repast-interest

------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest