Failure to import bean definition file - eclipse

I have an Eclipse Mars project compiling to a jar file with a Spring bean definition file in the following path: my-project.jar/spring/config.xml
This artifact is included in another Eclipse webapp project (via Maven). When I expand the contents of the compiled war file, I can see that the my-project.jar file and its contents (i.e. config.xml) exist.
Inside the webapp, I have a Spring definition file (WEB-INF/classes/spring/context.xml) and it has an import statement for config.xml as follows: <import resource="classpath:spring/config.xml"/>
I run into issues, when I launch the webapp (via Eclipse). I get the following exception:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [data.xml]
Offending resource: class path resource [spring/context.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:spring/config.xml]
The file is in the classpath, so I assume there is some class loader issue that I can't figure out. Strangely, this issue is inconsistent. There was once or twice that starting up the webapp produced no errors.

Put a slash in front when your bean definition XML file is in some folder:
<import resource="classpath:/spring/config.xml"/>

Related

Error when building Scala Maven project: Could not find or load main class scala_maven_executions.MainWithArgsInFile

Error when building a Maven project using maven-scala-plugin:
[ERROR] Error: Could not find or load main class scala_maven_executions.MainWithArgsInFile
Then reason is that settings.xml file was copied from Windows to OS X without modification, however it contained Windows-specific local repository path:
<localRepository>C:\Users\<username>\.m2\repository</localRepository>
Should be changed to:
<localRepository>/Users/<username>/.m2/repository</localRepository>

Intellij class path setting when build a jar for maven project

when running the jar in command line, throw this exception:
java.lang.ClassNotFoundException
When building jar in intellij, we need set the manifest properties, like main class, class path, where could I find the right setting for this? it is not in the manifest file

Trouble running jar file created by Eclipse

I exported my Eclipse project as a runnable Jar file, added a manifest, as well as the appropriate class files with the command:
jar cfm JarFile.jar manifest.txt *.class
However, when I try to run the jar file with
java -jar JarFile.jar
I get the error that it "Could not find or load main class" etc. etc.
The structure of my manifest.txt file looks like this:
Main-Class: EclipseProjectName.src.packagename.mainclassname
(With a carriage return at the end)
Is something wrong with my manifest file? If not, what may be the reason that the main class cannot be found?
Thank you!
The manifest file extension should be .mf i.e manifest.mf. See here for jar file specification
Suggest to use fat jar eclipse plugin for exporting java projects as runnable jars.
Edit
Correct the content of manifest.txt as shown below
Main-Class: EclipseProjectName.src.packagename.mainclassname
project name and src are not required. Refer this
The entry in the META-INF/MANIFEST.MF entry in the finished jar file should be
Main-Class: packagename.mainclassname
and should correspond exactly to
/packagename/mainclassname.class
in your jar file (or jar file_s_ if you use Class-Path too).

Spring JPA Hibernate Maven - Error : No persistence units parsed from {classpath*:META-INF/persistence.xml}

While testing the application created in Getting Started With JPA in Spring 2.0 tutorial I am getting following error. I have created Maven Project in eclipse. Here is the part of the structure of the project
ecotraveler
src
main
java
com
enam
resources
config
applicationContext.xml
WebContent
META-INF
persistance.xml
While running test class I am getting No persistence units parsed from {classpath*:META-INF/persistence.xml}
Can anyone tell what could be the problem? It seems application is unable to find specified path. I double check that WebContet/META-INF is in eclipse build path.
You need to put the META-INF directory in you resources directory, not in the WebContent
You spelt "persistence.xml" wrong; it has no "a"

Issue in executing Spring Web project in Eclipse on Tomcat server

I have a Spring web project that uses Maven to compile/build. There is no issue in building the project. I am trying to run the project in Eclipse (3.3.2) on Tomcat (v6) server.
As part of Spring project, I have a spring-servlet.xml file in WEB-INF directory. This file includes another resource xml file that has datasource configuration.
<import resource="classpath:${datasourceInclude}.xml"/>
Now when the project is compiled using Maven, it resolves the variable ${datasourceInclude} and set it with appropriate values resulting in spring-servlet.xml with proper values.
<import resource="classpath:datasourceLocal.xml"/>
But when I tried running the project in Eclipse (Tomcat), I am getting following error:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:${datasourceInclude}.xml]
Offending resource: ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [${datasourceInclude}.xml]; nested exception is java.io.FileNotFoundException: class path resource [${datasourceInclude}.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
...
...
Basically when I starts Tomcat, it tries to pick the spring-servlet.xml from /src/main/webapp/WEB-INF folder which has ${datasourceInclude} variable.
Can anyone tell me how to fix this issue so that I dont have to change spring-servlet.xml and add hard code value in place of ${datasourceInclude} variable.
Try to add war:inplace to the list of goals executed for resource filtering in the Maven project configuration page.
Right-click on your project, then go to Properties > Maven > Lifecycle Mapping and add war:inplace to the Goals to invoke on resource changes as shown below:
Who's responsible for resolving the property/variable name in your Spring XML? This is done at compile time via Maven or is it supposed to happen at runtime? If at runtime, are you using Spring's PropertyPlaceholderConfigurer?