I have the following maven project setup. I have a parent module with a number of child modules one which is a spring boot application. I am trying to build a "layered" spring boot application jar for that child module but unable to.
The child module that is a spring boot application has a dependency management section that includes spring-boot-dependencies as described here : https://docs.spring.io/spring-boot/docs/2.1.11.BUILD-SNAPSHOT/reference/html/using-boot-build-systems.html. The "build" element of this child module declares the spring boot maven plugin as described here : https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/html/#repackage-layered-jars-tools .
When the "layers" are disabled , i get a "fat" jar and a folder structure with files i would expect. But when "layers" are enabled, i get a fat jar that is corrupt. The corrupt jar has the same folder structure as the non-layered jar but in addition has an empty folder called "BOOT-INF(1)" which winzip says is a result of an invalid file name. The BOOT-INF folder itself in the layered jar looks identical to the non-layered jar(except for new classpath.idx and layers.idx files) but has no layers whatsoever. Interestingly enough the classpath.idx and layers.idx files under BOOT-INF folder have the correct entries when layering is turned on. I get identical results when i provide my own custom layers.xml file except that layers.idx matches my layers in the custom layers.xml file.
I am unable to post actual code because of company restrictions.Has anyone come across a similar problem?I tried the -X maven debug option but i couldn't spot what was going wrong during the "repackaging" phase. I am using spring boot 2.3.2.
Related
I am using STS to develop a large Spring Boot based application. We have multiple maven projects and a parent project to include them all. Each project has own testing code and config files.
When I run the Spring Boot application in the main entry class. The test-classes folder of the depended projects will be loaded into the app running classpath, that causes some conflict of spring bean definition. I have to config every project removing [src/test/java and src/test/resources] from the 'source folders on build path'.
The whole project structure is like below:
app-parent
sub-app-1
sub-app-2
sub-app-3
main-app [running from this project]
main-app project has dependencies on the sub-app-1 ~ 3.
Is there any way to let STS (Eclipse) run a Java App excluding the test-classes folder from classpath? I really do want the testing code under source folder but not have them when the App run.
Besides, I tried open the [run configuration], but it can only add more file to the classpath.
As pointed out by #torsten-crass, verify that Exclude test code is ticked in your Classpath tab of Run configurations in Eclipse.
Here is the screenshot.
Am a beginner with netbeans IDE. I want to know that web.xml file in Netbeans hierarchy is same as that of pom.xml file in Eclipse IDE.
Where as in Eclipse, when we create a project it comes with pom.xml file. We can modify when we need to modify or to add dependencies. So, how about in Netbeans? web.xml work as similar to pom.xml
I think you got this all wrong. Please read through some materials.
web.xml - deployment descriptor
Java web applications use a deployment descriptor file to determine how URLs map to servlets, which URLs require authentication, and other information. This file is named web.xml, and resides in the app's WAR under the WEB-INF/ directory. web.xml is part of the servlet standard for web applications.
A web application's deployment descriptor describes the classes, resources and configuration of the application and how the web server uses them to serve web requests. When the web server receives a request for the application, it uses the deployment descriptor to map the URL of the request to the code that ought to handle the request.
pom.xml - project object model
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/test/java; and so on.
The POM was renamed from project.xml in Maven 1 to pom.xml in Maven 2. Instead of having a maven.xml file that contains the goals that can be executed, the goals or plugins are now configured in the pom.xml. When executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.
Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.
Go through the below pages.
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
https://cloud.google.com/appengine/docs/java/config/webxml
I have a Spring MVC based rest api API_1. I want to create another api API_2 which will use all the same system vars of API_1. Basically I want to create a separate Spring boot rest service and add it as a dependency to API_1.
Is i possible to do this? I don't want to change packaging type from war to ear.
Only thing is I want this api separate project is because I think this feature can be used by other api's accross the project.
I was thinking if I can somehow load API_2 in API_1 after adding the dependency and some configs in web.xml or pom xml (adding some plugin)
If you don't want to create a jar out of war, you can consider maven overlays
An overlay of a WAR file, is simply a Maven project that uses another
project's WAR output as a dependency, rather than a project's JAR.
When the overlay project is built, the underlying project's WAR file
is exploded and files in the overlay project added to it. If an
overlay project has a file with the same path and name as a file in
the underlying WAR it will replace it.
I have a very specific problem dealing with GWT. I have a web application and a jar file which contains the business logic. Inside this jar I use dozer mapper and I have the related config file inside the jar itself. The config file is under META-INF/dozer_mappings.xml. While in hosted mode it works perfectly, in web mode it has a problem. It says:
Unable to locate dozer mapping file [/META-INF/dozer_mappings.xml] in the classpath!
Actually I don't understand why it should change: if the file is not in the classpath it should not work in both the environments... Of course all my libraries are in the WEB-INF/lib folder. The one with the dozer configuration is there as well.
I've this problem using STS: I'm building a simple Spring app, just to try out features like MVC and persistence. Now I've created something very simple, out of a bunch of tutorials for Spring 3, that I'm using. The application fails with this, during server startup:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
but I've org.springframework.orm in web-inf/classes folder (I even tried putting it in web-inf/lib). As I copied these libs there, the came out in Web App Libraries folder. Building this project in STS works fine as this dependency is set up in build path throught project properties, but how do I transfer the libs to the web app? (I'm using Tomcat 6 as it is the server I'm going to use sometime in the future for production). Is this a config problem of my XML? Or am I just missing the right way to put this lib? (I encountered the same problem before, but adding the needed lib in classes worked it out). More than this I that if I browse inside my workspace to the folder where the working folder of tomcat should be, I can't find any work directory and any commo
Go to the Servers view and double click on Tomcat Server which will open up a Tomcat Overview page. This will show you the server path and deploy path which Eclipse is using to publish your webapps to.
For example, mine are:
Server path: .metadata\.plugins\org.eclipse.wst.server.core\tmp0
Deploy path: wtpwebapps
Now in a Command Prompt (or Explorer) browse to %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps and you should see your webapp. Go into the WEB-INF\lib directory and check if your jar is there.
A few things to try:
If the jar is not in WEB-INF\lib, you might need to republish it. Right-click on the Tomcat in the Servers view and click Publish. Does it appear? If not, Right-click on the Tomcat again and this time select Clean... which will clean out everything and republish. If this doesn't work, the brute force approach would be to delete the files manually and then tell Eclipse to republish them.
Clean your work directory, by right-clicking the webapp under Tomcat in the Servers view and selecting Clean module work directory. Or do it manually by deleting from %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost
You should also try closing-reopening/cleaning/rebuilding/refreshing your webapp project just in case Eclipse hasn't picked up the changes.
You need to put the various Spring JARs into your WEB-INF/lib directory (WEB-INF/classes is no use for JAR files).
You don't just need org.springframework.orm, you need most of them (see here for dependency diagram).
At least the libary jar files must be located at WEB-INF/lib within your war file. And you only need to deploy the war file to your productiv web server.
If you use STS but your Project is not a Maven project: then you need to put the files in <projectRoot>/WebContent/WEB-INF/libs .(to build the war with Eclipse/STS you need to execute Export/Web/WAR file.)
If you use Maven, then you need the specify your dependencies in the pom.xml, and use maven to package the war (run as/Maven package).