1

I want to calculate the memory usage of an object (Treap in a package with name TreapDS)that I created. I found that I need to follow of these steps based on this page. I always use Eclipse so I am not familiar with running Java code with commands. I asked question how can I build jar files based on that page in this page but I did not receive any answer. This is the hierarchy of my packages:

Indexing
| --- bin
|---- MemoryUsage
              | -- mainfest.MF
              |  -- Myagent
| --- src
       |--- treapDS
       |      |--- Treap
       |---- MemoryUsage
              | -- TestCase
              |  -- Myagent

I can create a jar file based on running the command in this address

Indexing/bin$ jar -cmf MemoryUsage/manifest.MF agent.jar MemoryUsage/MyAgent.class

It create agent.jar in bin folder and when I extract this jar file in consist of two folders MemoryUsage which contains Myagent.class and folder META-INF which contains MANIFEST.MF

but when I run the following command I got the exception and I do not know how to solve it by mentioning the address of the Treap. Is there any way to do this with eclipse?

/Indexing/bin$ java -javaagent:agent.jar -cp MemoryUsage/TestCase

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.NoClassDefFoundError: treapDS/Treap
    at MemoryUsage.MyAgent.premain(MyAgent.java:9)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: treapDS.Treap
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more
FATAL ERROR in native method: processing of -javaagent failed
Aborted (core dumped)

I read these pages 1 2 but I could not solve my problem.

Community
  • 1
  • 1
Suri
  • 209
  • 1
  • 4
  • 10

1 Answers1

0

That is because treapDS isn't the same as TreapDS. Class names are case sensitive! The stack trace is pretty clear: the class loader is attempting to load treapDS.Treap instead of TreapDS.Treap and the former does not exist.

Fix your source code and recompile to have proper case sensitive spelling everywhere and it should go away.

Presumably the reason 'everything compiled' the first time is because you develop on an OS without proper case sensitive file paths.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
user268396
  • 11,576
  • 2
  • 31
  • 26
  • @Mike Samuel @ user268396 The name of package is **treapDS** in all part of my code. I wrote it in hierarchy wrong; sorry about that. How can I prepare case sensitive file path? – Suri Jan 17 '16 at 15:05