You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by yihfeng <yh...@gmu.edu> on 2010/07/21 17:11:16 UTC

not able to read config file from java code within a bundle

Hello,

We are using ServiceMix 4.2 (with felix engine) to host cxf web services. 

Our java code cannot see the config file "dataSourceApplicationContext.xml"
when the bundle is deployed to serviceMix. We can execute the same code in
eclipse without issue (we added the config dir to the classpath in eclipse)

------------
java code:
------------

ApplicationContext ctx = new
ClassPathXmlApplicationContext("file:dataSourceApplicationContext.xml");


Note:  if the full qualified path for the config file is used, the code
works fine.

ApplicationContext ctx = new
ClassPathXmlApplicationContext("file:/Users/dev/workspace/FOS/core/src/main/resources/dataSourceApplicationContext.xml");


Could anyone show how to define/set the classpath in POM plugin OR in the
beams.xml to make the config file visible?


Here is the beans.xml and POM plugin.

------------
beans.xml:
------------

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
	<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

	<jaxws:endpoint id="fosService"
		implementor="edu.gmu.fos.core.ws.impl.FosServiceImpl"
address="/FOSService">
	</jaxws:endpoint>

</beans>

--------------
POM plugin:
--------------
                    <plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<version>1.4.0</version>
				<extensions>true</extensions>
				<configuration>
					<instructions>
					
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
						<Export-Package>
							org.apache.commons.dbutils;version="1.1",
							edu.gmu.fos.core.db;version="${pom.version}",
							edu.gmu.fos.core.ws;version="${pom.version}",
							edu.gmu.fos.core.ws.impl;version="${pom.version}",
							org.springframework.context.support;version="2.5.6"
						</Export-Package>
						<Bundle-ClassPath>.</Bundle-ClassPath>
						<Require-Bundle>
							org.apache.servicemix.bundles.commons-dbcp,
							org.apache.cxf.bundle
						</Require-Bundle>
					</instructions>
				</configuration>
			</plugin>



ANY HELP is appreciated.




-- 
View this message in context: http://servicemix.396122.n5.nabble.com/not-able-to-read-config-file-from-java-code-within-a-bundle-tp1727886p1727886.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: not able to read config file from java code within a bundle

Posted by yihfeng <yh...@gmu.edu>.
Freeman,

I am not sure what I changed, but now I am able to use classpath prefix to
read the config file within the bundle.

private static ApplicationContext ctx = new
ClassPathXmlApplicationContext("classpath:dataSourceApplicationContext.xml");
    private static DataSource spacer_ds = (DataSource)
ctx.getBean("spacer_ds");  
    
Will post more if I found out why.

Thanks for looking into this.
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/not-able-to-read-config-file-from-java-code-within-a-bundle-tp1727886p1861476.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: not able to read config file from java code within a bundle

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

Could you append your testcase(which I can build and deploy),  I'll  
play with it when I get chance.

Freeman
On 2010-7-22, at 下午10:03, yihfeng wrote:

>
> Thanks, Freeman, for the quick response.
>
> Unfortunately, I tried the following, both did not work.
>
> ApplicationContext ctx = new
> ClassPathXmlApplicationContext 
> ("classpath:dataSourceApplicationContext.xml");
>
> ApplicationContext ctx = new
> ClassPathXmlApplicationContext 
> ("classpath*:dataSourceApplicationContext.xml");
>
> Any other suggestion might allow java code to read a config from the  
> bundle
> itself?
>
>
> We now use "import source" within beans.xml to load the above config  
> file.
>
> 	<import resource="classpath:dataSourceApplicationContext.xml" />
>
> We also changed our java code to use spring bean defined in the  
> above config
> file to make our application works.
>
> Shouldn't there be an easier way to read a config file from the java  
> code
> within a bundle?
>
>
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/not-able-to-read-config-file-from-java-code-within-a-bundle-tp1727886p1842315.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang

------------------------
Open Source SOA: http://fusesource.com
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org


Re: not able to read config file from java code within a bundle

Posted by yihfeng <yh...@gmu.edu>.
Thanks, Freeman, for the quick response.

Unfortunately, I tried the following, both did not work.

ApplicationContext ctx = new
ClassPathXmlApplicationContext("classpath:dataSourceApplicationContext.xml"); 

ApplicationContext ctx = new
ClassPathXmlApplicationContext("classpath*:dataSourceApplicationContext.xml"); 

Any other suggestion might allow java code to read a config from the bundle
itself?


We now use "import source" within beans.xml to load the above config file.

	<import resource="classpath:dataSourceApplicationContext.xml" />

We also changed our java code to use spring bean defined in the above config
file to make our application works.

Shouldn't there be an easier way to read a config file from the java code
within a bundle?

 
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/not-able-to-read-config-file-from-java-code-within-a-bundle-tp1727886p1842315.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: not able to read config file from java code within a bundle

Posted by Freeman Fang <fr...@gmail.com>.
On 2010-7-21, at 下午11:11, yihfeng wrote:

>
> Hello,
>
> We are using ServiceMix 4.2 (with felix engine) to host cxf web  
> services.
>
> Our java code cannot see the config file  
> "dataSourceApplicationContext.xml"
> when the bundle is deployed to serviceMix. We can execute the same  
> code in
> eclipse without issue (we added the config dir to the classpath in  
> eclipse)
>
> ------------
> java code:
> ------------
>
> ApplicationContext ctx = new
> ClassPathXmlApplicationContext 
> ("file:dataSourceApplicationContext.xml");
>
Hi,
How about use
ApplicationContext ctx = new
ClassPathXmlApplicationContext 
("classpath:dataSourceApplicationContext.xml");
instead?
Ensure that dataSourceApplicationContext.xml exist in your bundle jar.

Freeman

>
> Note:  if the full qualified path for the config file is used, the  
> code
> works fine.
>
> ApplicationContext ctx = new
> ClassPathXmlApplicationContext("file:/Users/dev/workspace/FOS/core/ 
> src/main/resources/dataSourceApplicationContext.xml");
>
>
> Could anyone show how to define/set the classpath in POM plugin OR  
> in the
> beams.xml to make the config file visible?
>
>
> Here is the beans.xml and POM plugin.
>
> ------------
> beans.xml:
> ------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:jaxws="http://cxf.apache.org/jaxws"
> 	xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
>
> 	<import resource="classpath:META-INF/cxf/cxf.xml" />
> 	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
> 	<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
> 	<import resource="classpath:META-INF/cxf/osgi/cxf-extension- 
> osgi.xml" />
>
> 	<jaxws:endpoint id="fosService"
> 		implementor="edu.gmu.fos.core.ws.impl.FosServiceImpl"
> address="/FOSService">
> 	</jaxws:endpoint>
>
> </beans>
>
> --------------
> POM plugin:
> --------------
>                    <plugin>
> 				<groupId>org.apache.felix</groupId>
> 				<artifactId>maven-bundle-plugin</artifactId>
> 				<version>1.4.0</version>
> 				<extensions>true</extensions>
> 				<configuration>
> 					<instructions>
> 					
> <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle- 
> SymbolicName>
> 						<Export-Package>
> 							org.apache.commons.dbutils;version="1.1",
> 							edu.gmu.fos.core.db;version="${pom.version}",
> 							edu.gmu.fos.core.ws;version="${pom.version}",
> 							edu.gmu.fos.core.ws.impl;version="${pom.version}",
> 							org.springframework.context.support;version="2.5.6"
> 						</Export-Package>
> 						<Bundle-ClassPath>.</Bundle-ClassPath>
> 						<Require-Bundle>
> 							org.apache.servicemix.bundles.commons-dbcp,
> 							org.apache.cxf.bundle
> 						</Require-Bundle>
> 					</instructions>
> 				</configuration>
> 			</plugin>
>
>
>
> ANY HELP is appreciated.
>
>
>
>
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/not-able-to-read-config-file-from-java-code-within-a-bundle-tp1727886p1727886.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang

------------------------
Open Source SOA: http://fusesource.com
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org