GWT hosted mode and tomcat deploy differences - gwt

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.

Related

Spring boot maven plugin and layers

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.

dependency web application inside another web application

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.

MyBatis looking for xml files in Tomcat directory

I'm testing a web application with Eclipse + Tomcat, Eclipse deploys the web application files and launches Tomcat, and the application runs fine. But when MyBatis is trying to open it's XML configuration files, it looks for them in
C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\persistence\db\oracle.xml
instead of the correct place:
C:\workspace\mywebapp\src\persistence\db\oracle.xml
Where is MyBatis supposed to look for XML files?
EDIT:
This is where I specify the relative path:
String cfgFile = "persistence/db/oracle.xml";
Reader reader = Resources.getResourceAsReader(cfgFile);
session.put(db, new SqlSessionFactoryBuilder().build(reader));
Resources.getResourceAsReader looks files in classpath. For web application running in tomcat classpath consist of WEB-INF/classes and all jars from WEB-INF/lib and tomcat folders like $TOMCAT_HOME\lib.
The issue you encounter most probably is caused by the fact that oracle.xml file is not added to deployment. It looks like c:\workspace\myweapp\src is not among source folder of eclipse project so eclipse doesn't copy files from it to the folder which is deployed to tomcat. Depending on your existing project structure you may need to create subfolder in src and add persistence with all subfolders there. This will allow you to avoid clash if some subfolder of src is already a source folder in eclipse. I would recommend to use maven project structure:
src
main
* java
you java source code here organized by package
* resources
persistence
I marked folders which should be added as source folder to eclipse with *.
Please note that it is not correct to say that C:\workspace\mywebapp\src\persistence\db\oracle.xml is a correct place to search for it. After you create a war to deploy it on production this path most probably will not be available at your production server. What you really need is to include persistence\db\oracle.xml to the war in appropriate place (under WEB-INF/classes).
Maybe you need another class loader 1. Try this:
String cfgFile = "persistence/db/oracle.xml";
ClassLoader classloader = Thread.currentThread().getContextClassLoader()
Reader reader = Resources.getResourceAsReader(classloader, cfgFile);
Notes
See Difference between thread's context class loader and normal classloader and you may want to see the code of org.apache.ibatis.io.Resources. You find it here.

deploying spring mvc web app to tomcat: classpath issue

I am developing a small web app using Spring MVC framework. Basically, the app provides web interface, where user can upload XML file and verify it against specific XSD file. I put my XSD file within "src/main/webapp/XSDfoler". I put this folder into my Tomcat's classpath. (I am using Tomcat embedded into my Eclipse). In my code, in order to access my XSD file I simply used
ClassPathResource("myXSD.xsd");
It works fine. Now, I created a .war file from my webapp and tried to deploy it to another standalone Tomcat. When trying to run it, it give NullPointer exception since it cannot locate "myXSD.xsd" file. So as I get it, I have to somehow include this file into classpath of this standalone Tomcat instance. I looked for some nice step by step tutorial or article explaining how to deploy webapp to a standalone Tomcat server after doing the development in IDE with embedded Tomcat. Could anyone please explain/help. Thanks!
Try
ServletContext context = httServletRequest.getSession().getServletContext();
InputStream is = context.getResourceAsStream("/XSDfoler/myXSD.xsd");
alternatively use getResource() instead of getResourceAsStream()

GWT: Using External Jar

I am trying to figure out how to use external jar in GWT project.
I referred http://www.vogella.com/articles/GWTModules/article.html and it worked perfectly.
But the example explained using another project being included in the GWT project's build path instead of including the jar of that project.
I know this should not make a difference but when I created the jar of the external project (including sources) and used it in the client GWT gave me following error:
The import com.person cannot be resolved
What would be the problem?
For using external gwt library jar file in your gwt eclipse project you have to add that jar file in library tab from java build path:
If you want to use external jar and use that jar classes in your client side. you have to inherit module package entry in client gwt module.gwt.xml
Just example a. com.test.Module2.xml so you have do entry like
<inherits name='com.test.Module2'/>