Monday, October 15, 2012

package com... does not exist


Problem :


We come across this common exception when we are compiling java programs at command line or thru build. There are few scenarios where you might face this common exception. Lets see how we can resolve this.

Exception I Encountered Was :


#########################################################################################
compile:
[echo] cmp_cb_cda_ext compile: Start
[unzip] Expanding: M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\lib\vgn\vgn-ext-links.jar into M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\tmp_build\classes
[javac] Compiling 35 source files to M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\tmp_build\classes
[javac] M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\java\com\collegeboard\cda\listener\render\EndEventListener.java:22: package com.collegeboard.cda.site.redirect does not exist
[javac] import com.collegeboard.cda.site.redirect.CBHTMLRedirectPublisher;
[javac] ^
[javac] M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\java\com\collegeboard\cda\listener\render\EndEventListener.java:23: package com.collegeboard.cda.site.redirect does not exist
[javac] import com.collegeboard.cda.site.redirect.CBHTMLRedirectUtil;
[javac] ^
[javac] M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\java\com\collegeboard\cda\listener\render\EndEventListener.java:24: package com.collegeboard.cda.site.redirect does not exist
[javac] import com.collegeboard.cda.site.redirect.RedirectVO;
[javac] ^
[javac] M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\im
plementation\src\cmp_cb_cda_ext\java\com\collegeboard\render\link\printer\CBRenderLinkPrinter.java:6: package com.collegeboard.cda.site.redirect does not exist [javac] import com.collegeboard.cda.site.redirect.CBHTMLRedirectUtil;
[javac] ^
[javac] ^
[javac] Note: M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\java\com\collegeboard\cda\render\CPRenderXmlPrinter.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: M:\build_rpsgenbldd40_wcm_r1.32.0\wcmvob\implementation\src\cmp_cb_cda_ext\java\com\collegeboard\cda\site\sat\CBSystemRelatedVideoes.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 14 errors
#########################################################################################

Solution :


Lets talk about this exception in three scenarios:

1) Thru Command line :
When we have few java programs in different packages which we are trying to compile, we often see this exception. When we are importing a java class file from different package we must make sure that the imported java class file is compiled and already availbe before the current java class file is being compiled. Please look at the examples below for a complete explanation

2) Thru build :
In companies to compile the complete project related classes we use build. Build.xml file takes care of building the files accordingly to our choice. When build throws this error, make sure the java source files are properly placed in respective projects and the build output folder is properly assigned for each project. Make sure the dependable class files are compiled first and then the dependent class files. Please take a look at the next section for examples.

3) When CVS is involved :
When we are trying to build the class files from CVS, we come across this issue often. Build fails and complains that the required project isnt availble. The actual issue will be the java source files will not be checkin properly or there might be a issue with the CVS checin. Generally when a complete folder is being checkin with files, the folders gets checkedin but the files dont. When you see the status it shows as files are checkedin. So make sure when you are checkingin the files under folder, make sure you checkin the folder first seperately and then the files individually. Many a times this results in successful compiling and happy smiles :)

I just hope this resolved your exception and has brought a smile on your face :)

Example :


Let us see the above scenarios in exmaples :

1) Command Line :
You have two packages one com.home.page and com.home. In com.home.page you have a file called one.java and in com.home you have two.java. One.java imports com.home.two.java. When you try to compile com.home.page.one.java file before com.home.two.java you will get "package com.homepage does not exist" exception. You need to make sure that you have compiled the com.home.two.java and the directory path matches with the import path you have mentioned.

2) Build :
In build make sure the dependent files are compiled before the dependable files so that the build doesn throw exception like "package com.collegeboard.cda.site.redirect does not exist". Make sure the build.xml files is wellformed and package output is properly organised.

3) CVS :
You have created three news files called one.java,two.java,three.java under a new folder called redirect. You want to checkin the complete folder redirect in CVS. You have first checin the folder redirect and then the three files one.java, two.java and three.java. If you tru to checkin at the folder level then the CVS will not checin the files properly and you will end up with "package com.collegeboard.cda.site.redirect does not exist" exception. So make sure you have properly checkedin the files.


Similar Exception :

     
- package com.collegeboard.cda.site.redirect does not exist
- cannot find symbol
- fileName.java uses unchecked or unsafe operations.

No comments:

Post a Comment