404 when deploying Grails 3.1.10 war to tomcat7 or tomcat8 - tomcat7

The closest stackoverflow question that explains my symptoms is here - How can I deploy a Grails 3.0.1 war file in Tomcat7?
I am in the process of upgrading a Grails 2.3.4 application to Grails 3.1.10 and everything is working with 'grails run-app'.
When i deploy to a war i get nothing but 404's for any url.
The war deploys without any error messages in catalina.out.
The tomcat access logs show my access attempts. (not linux problem?)
I can get to the tomcat manager, and the tomcat manager shows my app as "running" as true. (no errors)
Manager shows myapp-0.1 because the war file was myapp-0.1.war .. this is fine for now.
I am running Grails 3.1.10.
I have tried against Tomcat 7.0.55 as well as 8.0.92.
I have tried changing grails.serverUrl in application.groovy to various values. It is now:
//fix war name after get working
grails.serverUrl = "/myapp-0.1"
System.setProperty("server.contextPath","/myapp-0.1")
I have tried the above without "-0.1". (i was suprised to learn this was necessary - https://stackoverflow.com/a/23664531/104993)
I have tried changing "org.springframework.boo:spring-boot-starter-tomcat" from "compile" to "provided" in the build.gradle file.
Please let me know what I need to elaborate on. It's difficult to paste log outputs and config files. (i'm behind a firewall)

You add the following task to your build.gradle it will name the war what ever you want:
task wrapper(type:Wrapper){
war.archiveName='myWar.war'
}
Then when you deploy it should have the correct name and you can go to https://localhost:8080/myWar

Related

Running Spring application outside of an IDE (preferably OS shell)

https://www.pegaxchange.com/2018/01/24/java-web-project-with-spring-framework/ has instructions for creating a Java Web Project with Spring, without Maven. I am able to get it working in an Eclipse environment. It works as expected by doing “Run As” --> “Run on Server”.
When I kill Eclipse I get the Status 404 error (“The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.”). I have verified that the Tomcat Server is running from the XAMPP Control Panel.
How do I launch the application from an OS shell (Windows & Linux) so that I don't see the 404 error?
Its been a long time I haven't used java web projects without maven but if my memory serves me right, you should first export your project as .war file. Then deploy it to tomcat.
In eclipse right click your project select export and then select WAR file.
Copy your WAR file into webapps directory which is located in tomcat installation directory.
Rename the WAR file as you like if you want to serve you web app with a specific context name something like http://localhost:8080/myapp. If you do want to serve as root without a context name just rename it as "ROOT".
Run tomcat by command line <your-tomcat-installation-dir>\bin\startup.sh or it will be a .bat file for windows so you should end your command with .bat.
Or if you can start and stop by XAMPP panel this should do the same as well.
Also you can see this article for details on how to deploy a war file to tomcat.
I hope this helps. Cheers!

Springboot Strange Resource Loading Behavior

I'm working on a springboot 1.5.1 application that I'm trying to load a WSDL included in my resources directory in the wsdl directory. Depending on where my application executes I'm getting different results (command line, intellij, cloud foundry) and I can't seem to get all three to work at the same time.
I've tried several ways of locating the resource:
From prior to the migration to springboot we had this (worked in IntelliJ but not java -jar myboot.jar):
this.getClass().getResource("/wsdl/my.wsdl");
I switched it to the typically more correct version and got it to work in IntelliJ and java -jar but not Cloud Foundry:
this.getClass().getClassLoader().getResource("/wsdl/my.wsdl");
I switched it to use the Spring Resource Loader version and it worked in IntelliJ and CloudFoundry but not java -jar:
#Value("classpath:/wsdl/my.wsdl")
private Resource wsdlResource;
wsdlResource.getURL();
On the command line what I've noticed is that it seems to be thinking that BOOT-INF/classes is a JAR file (Note the ! after classes):
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL at: jar:file:/C:/dev/redacted/build/libs/redacted.jar!/BOOT-INF/classes!/wsdl/my.wsdl. It failed with:
JAR entry BOOT-INF/classes!/wsdl/my.wsdl not found in C:\dev\redacted\build\libs\redacted.jar.
From looking at IntelliJ's URL, it's referring to the actual source folder which explains why it seems to always work.
What is causing this and how might I universally load these class path resources successfully with springboot?

jhipster : angularjs files and browser cache

I am developping a Jhipster web app.
My problem is that when I update some angularjs files and then deploy the new war file in Tomcat7 the modifications are not taken into account, the clients pc is still reading the old angularjs file.
Is there a way(or a jhipster configuration) to tell the client pc to reload all angularjs file in order to be up to date?
Thanks you.
When you build your app with prod profile using mvn -Pprod package or gradlew -Pprod bootRepackage the web assets are minified and prefixed with a unique code in dist folder. An older version of same file has a different prefix so if it is cached it will not prevent the new one from being loaded.
If you don't see this behavior, it's probably because you didn't set the spring.profiles.active property to prod in Tomcat and so your app is running in dev mode and not using the files from dist.
If your frontend and backend are in the same war: 0.0.1-SNAPSHOT change this version in pom.xml before making a build to avoid angular caching issues.
If your frontend is split then go to: gulp/utils.js and change this version: '0.0.5-SNAPSHOT';

Team City: Cannot Redeploy to Tomcat7

I have a build configuration that uses the Team City deployer plugin.
I'm using a container deploy to deploy the war file to Tomcat.7.0.63 installed as a service on a Windows Server 2012 R2 box.
The first time I run the the build, the artifact (a war file_ deploys successfully.
The second time, and all subsequent runs, the deploy fails.
The error message:
Build failure message received: org.codehaus.cargo.container.ContainerException: Failed to undeploy
The log file error:
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Unable to delete
When I go to the webapps folder on the remote server, the war file is deleted, but the expanded folder is only partially deleted. Most files are gone, except for a png file.
I am not able to manually delete the folder because Tomcat still has a lock on it.
If I restart tomcat, I'm then able to run the build successfully (war file deploys).
One thought I had was to restart Tomcat before or after each deploy.
How would I restart Tomcat from TeamCity?
Or perhaps, does anyone have suggestions on how to fix this problem?
You can configure the Tomcat Context using the antiResourceLocking option, as detailed further in the online documentation. This does come with some trade-offs however; definitely worth reading the documentation in full and evaluating if it's a suitable option for your application.

Sphinx4 breaks on AWS Elastic Beanstalk, works on dev machine

I created a dummy Maven project that wraps CMU Sphinx4 in a servlet. The dependencies are sphinx4-core:1.0-SNAPSHOT and sphinx4-data:1.0-SNAPSHOT. When running locally (Eclipse) it works great, but then I deploy it to AWS Elastic Beanstalk and I get the following exception:
Property exception component:'null' property:'null' - java.io.FileNotFoundException: JAR entry edu/cmu/sphinx/models/en-us/en-us//means not found in /var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/sphinx4-data-1.0-SNAPSHOT.jar
edu.cmu.sphinx.util.props.PropertyException: java.io.FileNotFoundException: JAR entry edu/cmu/sphinx/models/en-us/en-us//means not found in /var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/sphinx4-data-1.0-SNAPSHOT.jar
Caused by: java.io.FileNotFoundException: JAR entry edu/cmu/sphinx/models/en-us/en-us//means not found in /var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/sphinx4-data-1.0-SNAPSHOT.jar
I suspect it's that double slash in there but I cannot explain why it doesn't happen on my dev machine (OSX).
thanks!
Edit:
My dev machine: OSX running Eclipse Luna with AWS plugin. I am using a J2EE project with a single servlet, and getting Sphinx JARs (core & data) through Maven. When I run the server in my dev machine (port 8080) I feed it a WAV file through a POST message, the file gets loaded correctly and I get the analysis as a textual response.
My prod machine: AWS Elastic Beanstalk. I deploy using AWS plugin. When I comment out the Sphinx part of the code, the server works (i.e. gets the file, and returns it to me, etc.)
If the problem is not the double slash, then the JARs are not being cooked right. This would make sense since the file it's looking for is not a class so the JAR cooking part of Maven should be told how to include resource files in the JAR it makes when it deploys.
Any idea how to do this ?
thanks again!
Double slash seems to be a problem on some JVMs, on other JVMs it works.
I've just committed an update to avoid double slashes. Please update sphinx4 and try again.
Turns out the problem was I was developing (OSX) on Java 7 and deploying to AWS to Tomcat/Java 8. Once I deployed to Tomcat/Java 7, everything worked as expected.

Resources