Tomcat overrides application.properties file in eclipse - java

I'm trying to run my camel application on external tomcat. There are 2 application.properties files present in my project, one under src/main/resources and other under src/test/resources. When I create war file using maven install command, it uses the application.properties file from src/main/resources (which is needed) but when I start the application using tomcat in eclipse, it is using application.properties file from src/test/resources. I've also removed classpath entry of src/test/resources from eclipse but no luck. I'm not really sure how is it picking the application.properties file from src/test/resources.
When I delete the application.properties file present under src/test/resources then it works fine i.e. then it picks the application.properties file present under src/main/resources.
We are using:
Oracle JDK 8
Spring 4.3.11.RELEASE
Tomcat 8.5
Camel 2.20.2
ActiveMQ 5.15.0
Maven Build Tool
Thanks in advance.

When Eclipse deploys a project to a server the important setting is the "Deployment Assembly", not the "Java Build Path". If you remove the src/test/resources folder from the deployment assembly, the files it contains will not be copied.

Related

Maven 3, Tomcat 8 deployment

currently I develop my applications with eclipse and I have configured tomcat's context.xml file in tomcat/config directory and all works fine.
But when I create war with mvn clean package command, I'd like to include into META-INF folder of the project, another customized context.xml file.
How can I do this?
I tried to create 2 profiles without success.
Thanks
Tomcat's context.xml file is located under $catalina_base/conf/ and can add things to that of your web application's context file. Add your (separate) web application's context.xml in Maven project at
src
main
webapp
META-INF
context.xml

Maven war build copy-resources: tomcat7:run does not recognise copied resources

I have a war project. A few static HTMLs need to be copied into the webapp folder before building war. To achieve this, added maven-resources-plugin copy-resources goal (process-resources phase). This is working fine as I can see the built war includes the copied files.
When I run this war using mvn tomcat7:run the path is not recognised (404).
However, when I deploy the war into a tomcat server, the path is accessible.
Any thoughts? Looks like tomcat7 plugin does not use the built war but accesses the files directly from src folder. Is this a bug or just how tomcat7 plugin works?
Have you tried using the additionalClasspathDirs param? from https://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/run-mojo.html
additionalClasspathDirs:
Additional optional directories to add to the embedded tomcat classpath.
Type: java.util.List
Since: 2.0
Required: No
if that doesn't work you can use maven-antrun-plugin see how to copy a file to tomcat webapp folder using maven?

package.properties not deployed by maven

I am using a package.properties file in my eclipse project (struts2). When running the application from eclipse, formatting date and time works fine but when I am deploying this project with maven to tomcat7, it seems that this file is not being included in war file and thus the formatting doesn't work. Can anyone please help?
Try placing the package.properties file at path src/main/resources of your maven project, Maven picks the files in resources directory.
Refer to this link to understand where to place the properties file:
Struts 2 – Resource bundle example
Alternatively if you don't want to place the files in resources directory then you can refer to this below link to understand how to pick properties file from src/main/java :
In maven how can I include non-java src files in the same place in the output jar?

Missing spring-web.jar when deploying with WTP to Websphere

I've build a spring-based web project in Eclipse using Maven. Dependencies and class path are correct and the deployment assembly also lists spring-web*.jar correctly. However, when I deploy it using WebSphere 8 from within Eclipse the mentioned JAR file is missing from the created libs folder under .metadata.plugins\org.eclipse.wst.server.core\tmp2*\WEB-INF\lib . This JAR however is listed under the module section as a submodule for the container. I wasn't able to find out, why this JAR is listed there and why it is not copied to the LIB folder.
It works with a Tomcat server, it works when I export the WAR and deploy it manually and it also works when I manually copy the JAR to the lib folder.
Q1: Is this specific to Websphere?
Q2: Why is SPRING-WEB listed as submodule and what effect has this?
Q3: How can I automatically deploy it correctly?
This seems to be a bug in WAS as reported here
You can either copy the missing JARs manually or you can use the "Run server with resources on server" option in the "Publishing settings for WebSphere Application Server" server settings.

Deploying war file in STS using gradle

I have a web project in STS, that iam looking to deploy in Tomcat. The build file for the project is written in GRADLE. Using GRADLE'S build script, a war file is generated in build/libs.
But STS looks for the war file in workspace/metadata/plugins/org.eclipse.wst.server.core/ folder.
Now If I manually copy the generated WAR file from build/libs to this workspace/metadata/plugins folder, and then start the tomcat, everything works fine but I am not able to debug using breakpoints in STS.
How do I make sure that the war file from build/libs gets moved to workspace/metadata/plugins folder?
And, Why is STS looking to find the war in workspace/metadata/plugins folder. As the app-server is tomcat, should it not be looking in Tomcat/webapps folder to find the war?
I am not a eclipse fan nowadays but did you run eclipse plugin? you can add it to the gradle file
apply plugin: 'eclipse'
and then just run
gradle eclipse
check Eclipse Plugin
I don't believe STS deploys/runs your war file directly. That is, if you select the project and say "Run on Server", STS/eclipse will generate an exploded war to the wtp.deploy directory defined. You can control/alter this by editing the "run configuration" for your server. Just go to the "Arguments" tab and change the setting for the "-Dwtp.deploy".
You should really only use this STS mechanism for development purposes - as it is invaluable for that. To deploy an actual warfile to Tomcat you have a variety of options. You can start a tomcat instance with the manager UI enabled and upload the war file from the Tomcat GUI, you can just manually drop the war file into Tomcat's deployment area, or probably your best option - extend your gradle build scripts to include deploying the generated war file to a tomcat server. Hope this helps some.

Categories