2

Here's the issue, i have this one project X that uses another project Y's services. Y was exported as jar file using eclipse and added to the project X build path. it so happens that the class that the spring loads "classService" in X can't load because there's something wrong with initializing dependency in the contructor of the remoteService which is in Y's StringEncryptorService. it says something about the class within a jar in Y. there's no compilation error, so the build path is good. Thanks Ahead. Any Answer will be appreciated

INFO: Initializing Spring root WebApplicationContext
ERROR org.springframework.web.context.ContextLoader:319 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'classService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.package.common.security.StringEncryptorService com.package.service.classService.stringEncryptorService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stringEncryptorService' defined in URL [jar:file:/C:/Users/user/git/project/Project/WEB-INF/lib/package-common-0.111.jar!/com/package/common/security/StringEncryptorService.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.package.common.security.StringEncryptorService]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64

I used commons-codec-1.8 which is in Y project. i know i can move it's jar file to Project X' referenced library, but i wonder if i can make it in Y so that when i make other project, say A, i can just export y as jar to A.

Edit: i think the issue is that the spring can't find the common-codec. since it is in under Project Y's library, the Project that i exported to Project X. can we do something so that the spring in Project X can scan through the library of Project Y? or specifically to the library of common-codec.jar. correct me if i'm wrong if i'm saying it wrong.

Answer: either add library explicitly to classpath of X by copying jar to it or add it as external jar to the project or add project to classpath in eclipse. since i want to let the library common-codec.jar to be always in Project Y library, we just added to application-context.xml of Project X:

<bean id="StringEncryptorService" class="PackagePathInProjectY.StringEncryptorService"></bean>

Special Thanks to: Harish Kumar. Thanks Buddy..


Vik2r
  • 145
  • 1
  • 2
  • 7
  • Its good to know which language. This is a java I know but i wonder if someone should tag it. I generally do for my own questions (as a secondary / tertiary tag) but not sure of best practice. – basarat May 30 '13 at 01:47
  • sorry.. mybad.. i'm new here.. :) – Vik2r May 30 '13 at 01:49

2 Answers2

0

org/apache/commons/codec/binary/Base64 is not found in your project, please add the commons-codec-1.8.jar in build path of X project ,another way is when you export the project Y remeber to add the commons-codec-1.8.jar in project Y together.

Hunter
  • 1
  • the first one didn't solve the problem. i exported also the common-codec-1.8.jar in Project Y, actually all of its library but it doesn't solve the problem. i have still this error when running tomcat. – Vik2r May 30 '13 at 02:21
0

There is definitely an issue with classpath in your deployed project to tomcat. Can you check if WEB-INF/lib has this library? If you are deploying the project as war then while building war or project X both libraries should be bundled and when war explodes on tomcat then both Y library and commons codec should be found in class path. You can bundle commons codec from Porject Y as part of build.

Harish

Harish Kumar
  • 528
  • 2
  • 15
  • what do you mean library? do you mean the tomcat library? i added it to Project X's Build Path. – Vik2r May 30 '13 at 05:24
  • By library I mean required jar files (project Y jar file and commons codec jar file). Are you deploying the project as war file or just using eclipse and have hooked tomcat on it to hot deploy the code? I used to work with a project where maven was used to build dependent projects and those were then downloaded and final war is made with all the libraries in it. But for development we used to change the code on eclipse and tomcat was able pick it up (not for everything). So code was run and debug from eclipse. – Harish Kumar May 30 '13 at 06:00
  • i'm not still deploying it as war file. i'm still doing the development and testing. i was just using the eclipse and run tomcat and check the view in localhost. i run it in eclipse, yeah. – Vik2r May 31 '13 at 03:11
  • Can you try adding Project Y as dependency in Project X, given they are in same Eclipse workspace? – Harish Kumar May 31 '13 at 04:16
  • You can do following too: I created folder called lib in X project and added the codec library to it. Created the jar by export facility in eclipse and then modified following entry in Manifest.mf file present in jar of project Y Manifest-Version: 1.0 Class-Path: lib/commons-codec-1.2.jar. This works fine – Harish Kumar May 31 '13 at 05:25
  • Please ignore above comment. I mixed up somethings and it does not work by manifest. So either add library explicitly to classpath of X by copying jar to it or add it as external jar to the project or add project to classpath in eclipse. Apologies for confusion. – Harish Kumar May 31 '13 at 05:52
  • yeah that's right... actually for now, we did the copying the common-codec.jar ni Project X.. thanks.. – Vik2r Jun 01 '13 at 00:13