aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Strange compile problem, maybe eclipse related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Strange compile problem, maybe eclipse related" Watch "Strange compile problem, maybe eclipse related" New topic
Author

Strange compile problem, maybe eclipse related

Enrico Palazzo
Greenhorn

Joined: Jul 19, 2012
Posts: 6
Hi there! Hope this is the right place for Eclipse-related questions. I stumbled upon a somewhat strange problem with implementing a javassist code in an eclipse project. I use a code that is a slightly adapted version of the code presented at http://www.javaranch.com/journal/200711/Journal200711.jsp#a4.

Here is the problem: when I use the two attached .java files in the default package of a new project, and add Javassist.jar to the build path (tbf at http://sourceforge.net/projects/jboss/files/Javassist/), things work fine as they should. However, when creating a new project with a new package (not default), adding the two .java files and the build path, and adding the package declaration to the .java files, an error occurs:

Exception in thread "main" javassist.CannotCompileException: by java.lang.NoClassDefFoundError: Evaluator
at javassist.ClassPool.toClass(ClassPool.java:1099)
at javassist.ClassPool.toClass(ClassPool.java:1042)
at javassist.ClassPool.toClass(ClassPool.java:1000)
at javassist.CtClass.toClass(CtClass.java:1140)
at tiny.Example2.main(Example2.java:25)
Caused by: java.lang.NoClassDefFoundError: Evaluator
at java.lang.ClassLoader.defineClass1(Native Method)
....

Would be great is someone would have a tip for a Java newbie. Thanks

file Evaluator.java:


file Example2.java:



Update: Maybe more like a "Javassist vs. Eclipse" problem - when I supply a Evaluator.class file in the \bin folder, the error message changes. Seems like Javassist expects the .class file to be in \bin, but Eclipse of course compiles it to \bin\package_name... Hints / workarounds would never the less be highly appreciated!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5842
    
    7

Actually, by default Eclipse compiles things into bin/packagename/...
Are you perhaps using the project name as the package name somewhere?
Or did you change the configuration for your project to change where class file go?
The files you posted have no package clause, usually such packageless classes can cause issues for various Java components.

If this doesn't help, post the full path name of your java source file (get it from Explorer, not from within Eclipse). Or actually, the full project contents would be better; to get that run this command from a command prompt from within the project's directory:

dir * /s /b


JBoss In Action
Enrico Palazzo
Greenhorn

Joined: Jul 19, 2012
Posts: 6
Hi Peter, thanks for the answer!
Yes, Eclipse indeed compiles to bin/packagename if one creates a package. If not, it compiles directly to bin/ (even if it denotes the package as (default package) in the eclipse explorer). And only in this case (no package) the code does work, that's why I provided it without package declaration. As soon as I use it in a package it does no longer work.

D:\Eclipse\test3>dir * /s /b
D:\Eclipse\test3\.classpath
D:\Eclipse\test3\.project
D:\Eclipse\test3\.settings
D:\Eclipse\test3\bin
D:\Eclipse\test3\src
D:\Eclipse\test3\.settings\org.eclipse.jdt.core.prefs
D:\Eclipse\test3\bin\tes
D:\Eclipse\test3\bin\tes\Evaluator.class
D:\Eclipse\test3\bin\tes\Example2.class
D:\Eclipse\test3\src\tes
D:\Eclipse\test3\src\tes\Evaluator.java
D:\Eclipse\test3\src\tes\Example2.java

Projectname (test3) != packagename (tes). Sorry, mixed up projectname and packagename in my last post, is corrected now.
I changed nothing about the configuration, tried several times with creating a new project.

My guess is right now that this is a Javassist problem - this package uses own class loaders, and the error message hints to a javassist compile error. To me it looks like Javassist is always trying to locate the Evaluator.class in the /bin folder, and I'm not good enough to change that with the given dokumentation of Javassist...
Enrico Palazzo
Greenhorn

Joined: Jul 19, 2012
Posts: 6
Solved it, sorry for keeping you guys busy. The code above works in a package when one provides the packagename in line 15. Assuming the two files are in package "tes", line 15 reads:

new CtClass[] { pool.makeClass("tes.Evaluator") });

I'm upset that kept me busy for one day now, though the solution is so obvious ;)
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5842
    
    7

Yes, from the post showing the project's contents it is obvious that you class' name is tes.Evaluator, so that is what you need to use to refer to it. I assume that your Evaluator.java source file also had a "package tes;" statement which you neglected to include when you posted he source.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange compile problem, maybe eclipse related