cargo-maven3-plugin: unable to add datasource - tomcat7

I am trying to configure datasources on a Tomcat using Cargo to allow people doing local tests of the software.
When I start the application using cargo, I have the following error:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mosesEntityManagerFactory' defined in class path resource [app-logic.xml]: Cannot resolve reference to bean 'appDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appDataSource' defined in class path resource [logic-datasource.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/app] is not bound in this Context. Unable to find [jdbc].
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)
...
The cargo maven plugin is configured in this way:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>1.10.4</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<zipUrlInstaller>
<url>https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/7.0.55/tomcat-7.0.55.zip</url>
</zipUrlInstaller>
<timeout>600000</timeout>
<output>${project.build.directory}/tomcat7x/container.log</output>
<append>false</append>
<log>${project.build.directory}/tomcat7x/cargo.log</log>
<dependencies>
[...] some dependencies like mysql, etc...
</dependencies>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/tomcat7x/catalina-base</home>
<properties>
<cargo.jvmargs>-Xmx4096m</cargo.jvmargs>
<cargo.datasource.datasource.mysql>
cargo.datasource.driver=com.mysql.jdbc.Driver|
cargo.datasource.url=jdbc:mysql://server:3306/app|
cargo.datasource.jndi=jdbc/app|
cargo.datasource.username=ignore|
cargo.datasource.password=ignore
</cargo.datasource.datasource.mysql>
</properties>
<configfiles>
<configfile>
<file>${project.basedir}/src/test/resources/tomcat7/tomcat-users.xml</file>
<todir>conf</todir>
</configfile>
<configfile>
<file>${project.basedir}/src/test/resources/tomcat7/context.xml</file>
<todir>conf</todir>
</configfile>
</configfiles>
</configuration>
</configuration>
</plugin>
The context.xml I provide contains:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
<ResourceLink global="jdbc/app" name="jdbc/app" type="javax.sql.DataSource" />
</Context>
and the logic-datasource.xml mentioned in the exception contains:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="appDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/app" />
</bean>
</beans>
I didn't find a way to debug what's happening by myself.
Do you know what is wrong looking at the configuration or how can I check what cargo is doing?
Thanks

Related

Deploy on glassfish server : no suitable driver for jdbc:derby

When I try to upload a maven spring project which uses JPA (I use derby) on a server, I receive an error he didn't find an suitable driver for jdbc:derby :
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [service.LocationGuide]: Constructor threw exception; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:derby://xxx.xxx.xxx.xx:portnbr/leuvenspeaks;create=true Error Code: 0.
I used these dependecies for JPA and derby
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.2.0</version>
</dependency>
And my Persistence unit :
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="LocationPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>domain.Location</class>
<class>domain.Story</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://xxx.xxx.xxx.xxx:portnbr/leuvenspeaks;create=true"/>
<property name="javax.persistence.jdbc.user" value="xxxx"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.password" value="xxxx"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
Thanks in advance!!
Put derby driver into $GLASSFISH_HOME\glassfish\domains\domain1\lib folder and restart server.
You can download Derby driver from here

How to inject #PersistenceContext in DAO generated by Hibernate3-maven-plugin

I wanna create a Java Application based on Hibernate-3 and Spring Framework. To get the process easy I found hibernate3-maven-plugin that is able to perform reverse-engineering of the existing database.
Here there's example of POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
<component>
<name>hbm2dao</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<componentProperties>
<revengfile>/src/main/resources/model.reveng.xml</revengfile>
<propertyfile>/src/main/resources/hibernate.properties</propertyfile>
<jdk5>true</jdk5>
<ejb3>true</ejb3>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>hbm2java</goal>
<goal>hbm2dao</goal>
</goals>
</execution>
</executions>
</plugin>
Then I set up the context of Spring:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="gomer" />
</bean>
<bean id="entityManager" factory-bean="entityManagerFactory" factory-method="createEntityManager"/>
<bean id="user" class="ru.tomtrix.first.db.UserHome">
<property name="entityManager" ref="entityManager"/>
</bean>
</beans>
It perfectly generates an Entity file and a DAO file except the following. In DAO file there's a EntityManager:
#Stateless
public class UserHome {
private static final Log log = LogFactory.getLog(UserHome.class);
#PersistenceContext private EntityManager entityManager;
... and this field hasn't got a setter! Eventually Spring throws the exception:
Invalid property 'entityManager' of bean class [ru.tomtrix.first.db.UserHome]: Bean property 'entityManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Of course it's not a good practice to write the setter manually. I think there is a way to inject a manager properly.
So how to do it without rewriting the generated file?
Corresponding information:
1) I'd like to create a stand alone application (and possibly run it in an Application Server like Tomcat)
2) model.reveng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://www.hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<table-filter match-name=".*" package="ru.tomtrix.first.db"/>
</hibernate-reverse-engineering>
3) persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="gomer" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="1234"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/users"/>
</properties>
</persistence-unit>
</persistence>
The problem is you are missing a part of the configuration. You need to tell Spring that you want to (also) use annotations for configuration. For this add the <context:annotation-config /> to your configuration and remove the setting of the entityManager
Next to that remove the calling of the factory method spring will handle all that for you.
Added tip use the version-less schemas insead of
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="gomer" />
</bean>
<bean id="user" class="ru.tomtrix.first.db.UserHome" />
</beans>
Your code might be problematic when you deploy it to a fullblown app server and you might run into issues with Spring and the EJB container competing over control of the beans. The hibernate plugin generates #Stateless session beans which in general will be picked up by the app. server (depending on which one you use).

Error scheduling jobs using Spring annotations

I am trying to schedule jobs using annotations Spring.. My configuration file is as follows:
<?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:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-
util.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-
task-3.0.xsd">
<task:annotation-driven />
<util:properties id="batchProp" location="application.properties" />
<context:property-placeholder properties-ref="batchProp" />
<bean id="indexer" class="package-name"></bean>
</beans>
and this is how I am invoking it:
public static void main(String[] args){
ApplicationContext appCont = new ClassPathXmlApplicationContext("Spring-Config.xml");
prop_file = appCont.getBean("batchProp", Properties.class);
}
My pom build segment is file:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>my_main_class</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
this works abosultely fine when I run it in Spring Tool Suite but throws an error when I run the jar file in the server.
The error is as follows:
Exception in thread "main"
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/task]
Offending resource: class path resource [Spring-Config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1416)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.mypackage.name.Indexer.main(Indexer.java:204)
Can someone please tell me what's going on?
Thank you!
Looks like there are no spring jar with "task" namespace (and maybe not only "task", but all namespaces: try to put "task:annotation-driven" after "util:properties" and you see other message) definition at servers classpath.
Check that server doesnt have old spring jars in its "libs" directory.
Try to put necessary spring jars to servers "libs" directory.

JBOSS 7.1.1 javax.persistence.PersistenceException PersistenceProvider in 'org.apache.openjpa.persistence.PersistenceProviderImpl not found

I am new to JBOSS and m stuck at basic deployment of app in JBOSS 7.1.1
I have created a webapp with persistent.xml as
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="mydummy-jpa" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:jboss/datasources/mydummyexample</jta-data-source>
<class>com.nsn.caobusiness.selfcare.entity.DummyTable</class>
<properties>
<property name="jboss.as.jpa.providerModule" value="org.jboss.as.jpa.openjpa" />
<property name="openjpa.Log" value="DefaultLevel=WARN,SQL=TRACE" />
<property name="openjpa.jdbc.DBDictionary" value="mysql(UseClobs=true)"/>
</properties>
</persistence-unit>
</persistence>
Datasource in my standalone.xml looks like :
<datasource jndi-name="java:jboss/datasources/mydummyexample" pool-name="mydummyexample" enabled="true" use-java-context="true" use-ccm="true" jta="true">
<connection-url>jdbc:mysql://localhost:3306/worldonstreet</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
When i deploy the application, i get following exception :
23:48:06,656 INFO [org.jboss.as.jpa] (MSC service thread 1-5) JBAS011401: Read persistence.xml for mydummy-jpa
23:48:08,000 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."SpringDatabaseTransaction.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."SpringDatabaseTransaction.war".INSTALL: Failed to process phase INSTALL of deployment "SpringDatabaseTransaction.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
**Caused by: javax.persistence.PersistenceException: JBAS011466:
PersistenceProvider
'org.apache.openjpa.persistence.PersistenceProviderImpl' not found**
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.lookupProvider(PersistenceUnitDeploymentProcessor.java:555)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deployPersistenceUnit(PersistenceUnitDeploymentProcessor.java:295)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:258)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleWarDeployment(PersistenceUnitDeploymentProcessor.java:194)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:118)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
I am stuck from entire day at this. Would appreciate any help from this forum.
Regards,
Legolas
I downloaded Apache Openjpa, extracted the jars, created a module in jboss under \JBOSS_HOME>\modules\org\apache\openjpa and changed my property in persistent.xml to
<property name="jboss.as.jpa.providerModule" value="org.apache.openjpa" />
module.xml looks like :
<module xmlns="urn:jboss:module:1.1" name="org.apache.openjpa">
<resources>
<resource-root path="openjpa-2.2.0.jar"/>
<resource-root path="serp-1.13.1.jar"/>
</resources>
<dependencies>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="javax.validation.api"/>
<module name="org.apache.commons.lang"/>
<module name="org.apache.commons.collections"/>
<module name="org.apache.log4j"/>
</dependencies>
</module>
it finally worked. :)
Thanks #lurscher for ur comments. It motivated me to carry on.

Running a Spring MVC application with Jetty gives "class path resource does not exist"

I'm new to Spring and I encountered a small problem: the web application runs perfectly when using Tomcat but has problem when running it with Jetty.
I run the following commands:
mvn package
java -jar target/dependency/jetty-runner.jar target/*.war
The error I get is:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-config.xml] cannot be opened because it does not exist
Part of my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
...
</dependencies>
<repositories>
...
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>7.4.5.v20110725</version>
<destFileName>jetty-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Part of my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
...
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
...
</web-app>
Part of my /WEB-INF/applicationContext.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
...
<import resource="classpath:spring-config.xml" />
</beans>
The relevant directories structure:
- src
--main
---java
----spring-config.xml
---webapp
----WEB-INF
-----applicationContext.xml
-----web.xml
-pom.xml
Seems to be a problem with the classpath definition but I don't know how to solve the problem. I already tried to specify the classpath with java -cp "..." ... or java -Djetty.class.path="..." ...
Any help is very appreciated!
Thank you.
spring-config.xml file should be in src/main/resources. XML files in the Java source directory won't be included on the classpath.
This is automatic if you use the jetty plugin and run with mvn jetty:run (or jetty:run-war).
Your CLASSPATH doesn't include the Spring context.
I'd advise you to package your app into a WAR and deploy that to Jetty. WEB-INF/classes is always in the CLASSPATH, so if you copy your Spring context XML to that directory the class loader will find them.
Do you need a ContextLoaderListener in your web.xml?
I see applicationContext.xml mentioned in your web.xml, but not spring-config.xml. That's the one the class loader is complaining about.

Resources