weblogic with spring hibernate mappingDirectoryLocations error

_wls_cls_gen.jarIssue

fromhttp://jaysensharma.wordpress.com/2009/12/28/_wls_cls_gen-jar-issue/

WebLogic10AndWebLogic10.3createsaJarfile(_wls_cls_gen.jar)whiledeployingourArchievedApplications(WARfiles).WhichincludesallthecontainsavailableinsidetheWEB-INF/classesdirectoryinsidethisjarfile(_wls_cls_gen.jar).IdidnotfindawaytotellWebLogicServertonottocreatethisJARfile,becauseitcreatesmanyissues.

Example:ifwehaveplacedaPropertyfileorSomeXMLfilesinsidethe“WEB-INF/classes”directorywiththename“test.properties”or“test.xml”thenWebLogicServerwillplacethisPropertyfileaswellinsidethe(_Wls_cls_gen.jar)filewhiledeployment…

zip:C:/bea103/user_projects/domains/Test_Domain/servers/AdminServer/tmp/_WL_user/testWebApp/8j5e1y/war/WEB-INF/lib/_wl_cls_gen.jar!/test.properties

NowifwewritethefollowingcodeinsideoutapplicationlikeServletthenitwon’tworkandwillfailwhilereadingthePropertiesfile:

Note:ManyframeworksusestheFollowingtechinquesandSometimesWebLogicCodecausesthisissue..(http://forums.oracle.com/forums/thread.jspa?messageID=4217650#4217650)…whichmaycauseourapplicationstofailwhilereadingjarArchievedresources.becausetheyusesthefollowingtechinquetoreadtheresourcesavailableinsideaJARfile:

——————————————-WRONG–APPROACH–BELOW———————

InputStream stream = null;

try {

Properties p = new Properties();

String path=Thread.currentThread().getContextClassLoader().getResource(“Info.properties”).getPath();

System.out.println(“—————-PATH: “+path);

p.load(new java.io.FileInputStream(path));

Host = p.getProperty(“Host”);

Pot = p.getProperty(“Port”);

User = p.getProperty(“User”);

Passwd = p.getProperty(“Passwd”);

System.out.println(“Property Key-Values:” +”\n”+ Host +”\n”+ Pot + “\n”+User+ “\n”+Passwd);

} catch (Exception e) {

e.printStackTrace();

}

——————

Toavoidtheaboveissue…weneedtochangeourcodelikefollowing:mostoftheFrameworksalsoneedtochangetheirimplementations…

————————CORRECT–APPROACH–BELOW——————-

InputStream stream = null;

System.out.println(“————————————”);

try {

Properties p = new Properties();

stream=this.getClass().getClassLoader().getResourceAsStream(“Info.properties”);

p.load(stream);

Host = p.getProperty(“Host”);

Pot = p.getProperty(“Port”);

User = p.getProperty(“User”);

Passwd = p.getProperty(“Passwd”);

System.out.println(“Property Key-Values:” +”\n”+ Host +”\n”+ Pot + “\n”+User+ “\n”+Passwd);

} catch (Exception e) {

e.printStackTrace();

}

———————

TheabovepieceofcodecanbeusedwheneverwewanttoreadaNon-Class/ClassresourcefrominsideaJARfile.

Thanks

JaySenSharma

__________________________________________

weblogicsucks!eitheryourewritethefunctionofspring,oryoujustusethefolderway.

besides:

ServletContext.getRealPathreturnsnull

http://ananthkannan.blogspot.com/2009/12/servletcontextgetrealpath-returns-null.html

AnotherweirdbehaviorfromweblogicwhenwebappisdeployedasWAR.ServletContext.getRealPath()returnsnullwhendeployedasWARbutitworksokwhendeployedasexploded.TherearetwowayswecanfixthisissuewhenyoustillwanttodeployasWARbutwouldliketogetoverwiththisissue:

1.Gotoserveradminconsole->Domain->Webapplications.ClickthecheckboxofArchivedRealPathEnabled.Thisshouldmakeanentryintodomainconfig.xmlasbelow.

     
<web-app-container>
          <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
       </web-app-container>

2.Secondoptionisatwebapplevelbyupdatingweblogic.xmlasbelow:

     
<container-descriptor>
         <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
       </container-descriptor>

Thevalueof<show-archived-real-path-enabled>setinthewebapphasprecedenceoverthevaluesetatthedomainlevel.Thedefaultvalueofthispropertyisfalse.

havereadanarticleagain,maybeIcantry

http://forum.springsource.org/showthread.php?t=45204&referrerid=14239

SeetheSpringReference4.7.2.3http://static.springframework.org/spring/docs/2.5.x/reference/resources.html#resources-wildcards-in-path-other-stuff

whichexplainswhy"classpath*:*.hbm.xml"doesn'twork.Youcangetittoworkifyouputyourhbm.xmlfilesinaspecifiedsubdirectory/package,forexample"classpath*:res/*.hbm.xml".OrifyouputtheminthesamedirectoriesasthecorrespondingJavaclasses,youcoulduse"classpath*:com/**/*.hbm.xml",assumingyourclassesareundertherootpackage"com".

ReplyWithQuote

相关推荐