I have been working on OSGI and Spring based applications for last few months and only now I have noticed that I don't specify which XML files to load for spring configuration. So how does Karaf know which files to load?
My project is Maven based and it uses maven-bundle-plugin to build OSGI bundle. As project is maven based it follows simple maven directory structure like below.
src/
main/java/
main/resources/ ---/here I'm keeping my XML configuratoin files.
pom.xml
Karaf uses spring dynamic modules (spring dm) internally to work with spring based bundles. It looks at following locations in your bundle to check for configuration files.
META-INF/MANIFEST.MF (if Spring-Context attribute is present)
META-INF/spring (if it contains XML files)
Reference http://uniqueexperiments.blogspot.com/2015/09/spring-osgi-bundle-how-does-karaf-know.html
So short answer is it has predefined locations and if you don't put files in there it won't load them.
Related
I have been working on migrating our code base onto Glassfish 3.1.2 using Java 7. I have been struck with this issue, where the deployment of EAR fails. I have an EAR, having modules, ejb.jar, couple of war files, along with lib directory having jar files to be shared across other modules within the EAR.
The issue is that ejb.jar refers to some spring bean definitions in lib/abc.jar file and is unable to find the spring file. The structure is like this:
EAR
ejb.jar (some spring files in here refer to lib spring file like, xyz.xml importing spring/abc.context.xml)
couple of war projects.
lib/lot of jar files (one of the jar here contains the spring file being referred from ejb.jar, note the file is inside directory inside the jar, like spring/abc-context.xml)
But the ejb jar cant load the bean definitions from lib/.jar
I have tried using the Manifest.MF inside the ejb.jar to refer to lib/abc.jar, but with no luck....
Not sure if there is some sort of problem with new GF 3.1.2, why its not able to respect the Manifest file. Any help will be much appreciated!
It looks like the JVM doesnt like the manually edited Manifest file and my guess is that windows is adding something like a carriage return etc. I managed to get it working by using the ant to generate the manifest file instead.
Thanks and hope that helps someone.
maven module spring application.
1 module is a spring mvc application, another is a non-web but spring managed application.
In my project root, I have:
/src/main/conf
This folder contains my non-web managed spring xml configuration. I added this folder to my class path in intellij.
IntelliJ doesn't pickup the file correctly, meaning I don't get code completion or anything (allot of the names etc. are in bold red i.e. intellij is telling me something is wrong). Can this be fixed somehow?
I have kept my spring mvc config file inside its module (not in the conf folder) because the code completion doesn't work and it's a pain to work with without the IDE helping. But it makes managing things during deployment harder.
In both of my spring config files (for the web app and non-web app), I have my dataSource settings hard-coded in the file, I want to extract this somehow into a properties file, how can I do this?
1 - You can have different spring configuration files all in the same folder, just you need to use different names form them. So, I would use src/main/resources instead to create a new folder in the maven project structure. You will avoid problems.
2- Datasource in both files? why? If you have already two spring configuration files, I would create a third one (application-context-dao.xml) and share the dataSource. How to move properties to a configuration file? See.
What is the difference between Java projects having pom.xml and web.xml? Can projects have both these configurations at the same time?
They're completely compatible. As a matter of fact, they perform completely unrelated tasks.
pom.xml is the configuration file for Maven projects. One of its goals is to provide assistance in the compilation and building of a project when using Maven. You can think of it as an ant build.xml file or a makefile Make file if you're not familiar to Maven (actually, it can provide a lot more functionality)
web.xml is the Java EE web application deployment descriptor, where you specify for instance servlets, servlet mappings and other aspects of a webapp.
What is Maven from the Apache Maven site.
What is web.xml file and what all things can I do with it? question on SO.
The two files have nothing to do with each other.
pom.xml - Maven configuration file. Controls the build process for
the project
web.xml - Web application configuration file. Controls the deployment
and configuration of the web application
The POM file really shouldn't be deployed with the application, its just for the build process.
web.xml is an indicator that the project is running in some kind of servlet container (possibly even a full-fledged Java EE container).
pom.xml is an indicator that the project is built using the Maven build system.
Those two things are entirely orthogonal, so any given project can have none, one or both of them.
The Pom defines any dependancy libraries, it is part of Maven. This tells maven what jar files to download and store in the lib folder of your site.
Web xml is how your web project is configured.
They can both coexist as they do different things.
POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named pom.xml. http://maven.apache.org/pom.html
yes you can have both configurations at the same time.
The pom.xml is for configure your project with Maven.
The web.xml is use in all Java EE project under Tomcat for example.
You can use both, Maven is for compile and deploy your project, Tomcat is your server.
Where should I have my Java source folder in the Maven web application architecture which results in a WAR?
Suggestions needed.
Maven web applications typically do not include java source code. The maven approach is to create a maven project for the "logic" of your web application (this will build into a jar) and create a second maven project for the webapp portion of your web application (this will build into a war). Then in the webapp portion, you introduce a dependency on the "logic" portion.
The end result is that when you build / test your logic jar (which contains servlets, etc), you will deploy that to your local repository and then build your war (which contains jsp pages, web.xml configs, etc).
The basic structure that is standard for Maven project is the following.
src/main/java Application/Library sources
src/main/resources Application/Library resource
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
Following the Maven recommendations and normal behavior makes it easier for other people familiar with Maven to easy recognize and understand the structure.
Source/Read more
Unless you explicitly specify it differently in your pom.xml (productive) Java source files in a Maven project go to src/main/java.
Java files always go in src/main/java and its advised to keep it that way.
Hi all i have very rare problem which needs to be solved.
Problem/issue:
I have a dynamic web project which is already built and i have war file of that project.
I need to apply some customizations on top of the war file given to me.
Using maven or ant am able to compile the custom code written by me and able to add produced class files to the war file.
But the this is happening for final war file build.
when i want to test my code in eclipse. the war file build and deployed in jboss plugin contains only the class files produced out of java files written by me..........
Please help me how can i modify the .classpath file of my project so that a jboss publish can build a war file using the dependent war file which can run on eclipse-jboss to test my custom code....
Advance Thanks.....
Not a rare problem.
What you need to combine two web applications (wars) together. You have your customization war on which you need to overlay the existing web application.
It looks like you have already solved it from build perspective and looking for Eclipse support. To my knowledge, Eclipse lacks support for this. You probably need to manually do the necessary configuration to make this happen.
It looks strange to me to have two WAR files.
Perhaps you have to consider to package your customizations in a JAR and inserting that jar in the original WAR file.
Otherwise, another solution, and what I do often with open-source project to customize is to have three projects in your workspace.
PRJ-src (with your original sources/JAR/WAR)
PRJ-custom (which depends of the previous one); This project contains only the new classes or custom spring xml files (with injection of my own classes)
PRJ (the merge of the two previous projects)
I create an Ant task in the 3rd project which takes the 1st project (PRJ-src) and merge with the 2nd project (PRJ-custom). This is possible to do so with Maven as well.
Then this is the only project I deploy in my app server (tomcat / jboss).