Using an external library in Java (Apache Commons and Eclipse)

Status
Not open for further replies.

mcmnky

Ars Tribunus Militum
2,625
Subscriptor
Howdy,

I'm trying to use one of the Apache Commons libraries (Math 3.3) in Java with Eclipse. (JDK 1.7 and Eclipse 3/JDT 3.7) And I can't get away from NoClassDefFoundError and ClassNotFoundException exceptions.

I have the appropriate import statements in the code, the project builds without errors or warnings, but I get an exception at runtime.

What I've tried:

I've added a lib folder to my project, put commons-math3-3.3.jar and commons-math3-3.3-javadoc.jar in there, and added the library to the build path.

I've created a new project in Eclipse, put the jar files in that project, and added that to the build path.

I've put the jar files in a new folder, added that folder to the PATH and CLASSPATH, and added that to the build path as an external library.

I've added a user defined library in Eclipse preferences and added that library to the build path. (Following this post:
http://www.java-forums.org/new-java/106 ... #post69802 )

The exception message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/transform/FastCosineTransformer
at Main.performDCT(Main.java:623)
at Main.filterACF_DCT(Main.java:244)
at Main.main(Main.java:148)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.transform.FastCosineTransformer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 3 more

Line 623:
Code:
FastCosineTransformer transformer = new FastCosineTransformer(DctNormalization.STANDARD_DCT_I);

I am no Java expert, but I've used external libraries in the past, e.g. the Java Media Framework.

Any ideas what I am missing? :confused:

Thanks.
 

Joel_B

Ars Praefectus
4,652
Subscriptor
[url=http:/civis/viewtopic.php?p=27243493#p27243493:3itque6w said:
mcmnky[/url]":3itque6w]Howdy,

I'm trying to use one of the Apache Commons libraries (Math 3.3) in Java with Eclipse. (JDK 1.7 and Eclipse 3/JDT 3.7) And I can't get away from NoClassDefFoundError and ClassNotFoundException exceptions.

I have the appropriate import statements in the code, the project builds without errors or warnings, but I get an exception at runtime.

What I've tried:

I've added a lib folder to my project, put commons-math3-3.3.jar and commons-math3-3.3-javadoc.jar in there, and added the library to the build path.

I've created a new project in Eclipse, put the jar files in that project, and added that to the build path.

I've put the jar files in a new folder, added that folder to the PATH and CLASSPATH, and added that to the build path as an external library.

I've added a user defined library in Eclipse preferences and added that library to the build path. (Following this post:
http://www.java-forums.org/new-java/106 ... #post69802 )

The exception message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/transform/FastCosineTransformer
at Main.performDCT(Main.java:623)
at Main.filterACF_DCT(Main.java:244)
at Main.main(Main.java:148)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.transform.FastCosineTransformer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 3 more

Line 623:
Code:
FastCosineTransformer transformer = new FastCosineTransformer(DctNormalization.STANDARD_DCT_I);

I am no Java expert, but I've used external libraries in the past, e.g. the Java Media Framework.

Any ideas what I am missing? :confused:

Thanks.

Maven.
 

Apteris

Ars Tribunus Angusticlavius
9,589
Subscriptor
I just tried your example code both with a JAR added to the build path, and with a user library referencing that JAR added to the build path, and could not reproduce the error. Perhaps you can try cleaning the whole project and rebuilding.

The true answer, however, is indeed Maven. I'm working on a project with a bunch of external dependencies myself, and I shudder at the thought of resolving them manually.
 

mcmnky

Ars Tribunus Militum
2,625
Subscriptor
Thanks for the tips. Yeah, I tried clean & build, recycling eclipse, rebooting the machine.

I'm looking into Maven. Seems like that will be the long-term solution, but right now I have an environment freeze--no patches, no new software, no changes not required to get my code running.

In the meantime, I've put the math3 source in a package in my project, and build with that rather than using the Apache jars. Not my preferred solution, but it works.

Thanks again for the pointers to Maven.
 
Maven is a build tool, not a library, meaning that you'd not be changing anything about the code you've produced.

You should also fire any human being who thinks "environment freeze" is a useful thing to tell to a developer. Doing things the wrong way because you've self-imposed a terrible restriction on yourself is pretty much the worst possible way to get things done.
 

Joel_B

Ars Praefectus
4,652
Subscriptor
[url=http:/civis/viewtopic.php?p=27245221#p27245221:1ile8zh3 said:
mcmnky[/url]":1ile8zh3]Thanks for the tips. Yeah, I tried clean & build, recycling eclipse, rebooting the machine.

I'm looking into Maven. Seems like that will be the long-term solution, but right now I have an environment freeze--no patches, no new software, no changes not required to get my code running.

In the meantime, I've put the math3 source in a package in my project, and build with that rather than using the Apache jars. Not my preferred solution, but it works.

Thanks again for the pointers to Maven.

Ouch. Maven is a required change to get your project working. Now you've checked in an external package into version control. If you don't have version control, please stop now and learn. If it's not your preferred solution then it's a bodge. Don't listen to non-Developers when making things work.
 

Joel_B

Ars Praefectus
4,652
Subscriptor
[url=http:/civis/viewtopic.php?p=27263599#p27263599:288xi3xh said:
SituationSoap[/url]":288xi3xh]Maven is a build tool, not a library, meaning that you'd not be changing anything about the code you've produced.

You should also fire any human being who thinks "environment freeze" is a useful thing to tell to a developer. Doing things the wrong way because you've self-imposed a terrible restriction on yourself is pretty much the worst possible way to get things done.

We have Mangers who like saying there is an "Environment Freeze" or a "Code Freeze" or whatever. I think they have watched too many hacker movies. We like to humour them and tell them right-o. But if we need to get things working we get things working.
 

mcmnky

Ars Tribunus Militum
2,625
Subscriptor
[url=http:/civis/viewtopic.php?p=27266035#p27266035:us6c7upx said:
Joel_B[/url]":us6c7upx]
[url=http:/civis/viewtopic.php?p=27263599#p27263599:us6c7upx said:
SituationSoap[/url]":us6c7upx]Maven is a build tool, not a library, meaning that you'd not be changing anything about the code you've produced.

You should also fire any human being who thinks "environment freeze" is a useful thing to tell to a developer. Doing things the wrong way because you've self-imposed a terrible restriction on yourself is pretty much the worst possible way to get things done.

We have Mangers who like saying there is an "Environment Freeze" or a "Code Freeze" or whatever. I think they have watched too many hacker movies. We like to humour them and tell them right-o. But if we need to get things working we get things working.

This is for a personal project, so the person freezing the environment is the the developer. And it's useful in my case for two reasons. Time spent on tools is time not spent coding. (I won't hesitate to invest time in tools that make the coding better or quicker, but in this case when there's a quick work-around, starting on a new tool with no clear definition of the time required or overall system impact wasn't justified.)

Also, it's useful to change only one variable at a time. The wrong way is to introduce this new tool, change some code, and then have no idea which is the root cause if a new issue pops up. Right now I'm restricting myself (as much as possible) to changing code. Something breaks, I'm not going to spend a lot of time hunting down the root cause; the issue will be in the code I changed.

As for freezes, IMHO Joel_B has it backwards. It's the PHB whose idea of what developers do is from TV and movies who think we can hit a constantly moving target. You can talk about agile and iterative processes all day, but you can't (or shouldn't) release until you've tested. You can't complete testing until the code is done. You can't finish coding until the requirements are done.

As for environment freezes, my group (and supporting folks from the Oracle, UNIX, and networking teams) has wasted most of the last 3 months because someone hasn't seen enough of the hacker movies Joel_B describes. Our servers were moved to a new data center. That move meant some servers would go from physical to virtual. (That's 2 variables right there. Already we're in trouble.) Despite assurances that all other factors would be equivalent between the old and new data centers, the new Oracle servers had a different "minor" revision. Minor, as in, no one on the server side felt the need to tell us on the application side. But not so minor it isn't causing errors in the application. A freeze of all factors other than those specifically in scope for the move would have saved many people much time and aggravation.

I realize I am not in a typical situation for most development. First, my day in a regulated industry, as in from time to time government agents will come in and look over our documentation. I'm better off with a well documented bug report than with a fix that isn't documented from start to finish. When we need to get things working, we get things working. After the function and technical specs are documented. And the risk analysis has been signed off by validation and SQA. And the test plan has been approved and executed. And all that put together for a final management sign-off and Go/No go decision.

(But mcmnky, if any changes have to go through that rigorous process, how did your Oracle servers end up on the wrong revision? And at this point mcmnky does a shot of red breast and reminds himself, if these folks knew what they were doing they wouldn't need him.)

Second, the Maven question is in regards to a personal project where, due to my own procrastination, I need to have a working prototype is short time doing something I'm not sure I know how to do. I have about 2 weeks to get it running by any means necessary. After that, if it takes the rest of my life to fix the shortcuts and work-arounds, so be it. (And yes, I see the fundamental contradiction between my first and second points.)

Anyway, I'll give Maven a shot tonight. Thanks for the inspiring words. :)
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
As for environment freezes, my group (and supporting folks from the Oracle, UNIX, and networking teams) has wasted most of the last 3 months because someone hasn't seen enough of the hacker movies Joel_B describes. Our servers were moved to a new data center. That move meant some servers would go from physical to virtual. (That's 2 variables right there. Already we're in trouble.) Despite assurances that all other factors would be equivalent between the old and new data centers, the new Oracle servers had a different "minor" revision. Minor, as in, no one on the server side felt the need to tell us on the application side. But not so minor it isn't causing errors in the application. A freeze of all factors other than those specifically in scope for the move would have saved many people much time and aggravation.

That's nothing to do with "Freeze". That's simply poor change management, something changed without the relevant people being informed/aware.
Note that despite *thinking* nothing else was changing it actually still did... The process failed.

Changing one thing at a time is very sensible plan in general though, and there's plenty of ways to achieve it. In your example trying a virtual install in the old data center would likely have highlighted this.
 

Joel_B

Ars Praefectus
4,652
Subscriptor
[url=http:/civis/viewtopic.php?p=27267241#p27267241:mo8jn9x4 said:
mcmnky[/url]":mo8jn9x4]

As for freezes, IMHO Joel_B has it backwards. It's the PHB whose idea of what developers do is from TV and movies who think we can hit a constantly moving target. You can talk about agile and iterative processes all day, but you can't (or shouldn't) release until you've tested. You can't complete testing until the code is done. You can't finish coding until the requirements are done.

Yes, but IMO you don't let non-Developers dictate what Developers can or can't do. "Freezes" should only be called by the Dev team, rather than external Managers.
 

mcmnky

Ars Tribunus Militum
2,625
Subscriptor
[url=http:/civis/viewtopic.php?p=27269765#p27269765:2313kf0x said:
Joel_B[/url]":2313kf0x]
[url=http:/civis/viewtopic.php?p=27267241#p27267241:2313kf0x said:
mcmnky[/url]":2313kf0x]

As for freezes, IMHO Joel_B has it backwards. It's the PHB whose idea of what developers do is from TV and movies who think we can hit a constantly moving target. You can talk about agile and iterative processes all day, but you can't (or shouldn't) release until you've tested. You can't complete testing until the code is done. You can't finish coding until the requirements are done.

Yes, but IMO you don't let non-Developers dictate what Developers can or can't do. "Freezes" should only be called by the Dev team, rather than external Managers.

What I will say to that is, what I have learned from watching (and being one of) people well-schooled in digital technology discussing legal issues (and particularly issues of intellectual property), what I have learned is humility.

It's hard to condemn a politician for describing the internet as a series of tubes when talking to people who don't understand the difference between copyright and trademark. (As an aside to the digression, we all talk about connections as pipes. How can some get so riled up that their 'pipes' have been called 'tubes'? (I'm sure there's a plumber who will scoff at my ignorance.))

So while I have felt the frustration of being immersed in digital technology while being subject to the whims of those who do not show understanding of that technology, there are business, financial, legal considerations I cannot pretend to understand. I have to trust my teammates while trying to educate myself. If a manager makes a decision which does not seem justified from a development perspective, does not mean that manager is wrong.

Aaaanyway, back to Maven. I had a whack at it last night. A few twist and turns aside, it was a quick set up, and my issue is resolved. My project builds and runs using the Apache jars.

Thank you!
 
Status
Not open for further replies.