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

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!

Related

How do I run a Spring Boot application from the applications root directory?

I'm not too sure how to best present my issue but I'll try my best.
I have made a spring boot application in Eclipse but when I go to the command prompt and enter where the application is(it's directory) and type the following line:
mvn spring-boot:run
I get the following error:
'mvn' is not recognized as an internal or external command, operable program or batch file.
In eclipse I right clicked over the application and did runs as -> maven Install.
Then I tried to right click over the application.java file and go run as -> but the option for "spring boot app" is not there?
I'm just trying to start Spring Boots default tomcat port.
I think you didn't add mavan bin to PATH variable
Please refer
https://maven.apache.org/install.html
If you want to build it from eclipse .Just right click and maven package/install it will make jar in target folder in root folder .Go to the target folder and do
java -jar jarname.jar

Manual Vaadin Project Deploy on Raspbian

For a project I want to do a performance comparison of different web-frameworks on a raspberry pi. Thats why I want to do only a manual deploy to mess around with it a bit.
I created a Vaadin project using maven and exported it as application.war file. I downloaded the tomcat-7 server and unzipped it. After that I gave the .sh files in the folder executable permission. Then I copied .war file in the webapps folder of tomcat. Finally I started tomcat by running sh startup.sh.
But when I try to open the page on my dev machine under ip:8080/application I only receive a timeout.
Did I miss something?

How to configure relative datasource file for SQLite?

I'm trying to configure a SQLite database for an Spring Web App. The thing is that I'm not able to reach the database file that I've created in src/main/resources using a relative path.
I've tried several configurations for the jdbc url but none of them worked:
jdbc:sqlite:mydb.sqlite (here I changed the file location to the project root)
jdbc:sqlite:${jdbc.url} (here I passed the url as a parameter thru PropertyPlaceholderConfigurer)
jdbc:sqlite:src/main/resources/mydb.sqlite
A weird thing that I realized about is that the app is using Eclipse's directory as the directory to find the database file. I mean, when I put jdbc:sqlite:mydb.sqlite it creates an mydb.sqlite on Eclipse's directory not in project's root.
Check the JVM system property named "user.dir" and set the path relative to it. It is the "current dir" of your java app. It can be different if you run from eclipse or from cmd line or inside webserver(tomcat).
So, System.getPropery("user.dir") will tell you current dir of your running app. Set the path to db relative to that directory.
I would say eclipse does not run your app from the project dir, as it should by default. Check your "run" settings in the eclipse.

jboss-as-maven-plugin: which directory does command "jboss-as:deploy" deploy an .ear to?

I am running jboss 7.1, maven 3, and a java ee6 application that generates an .ear
I am doing a mvn clean package jboss:as-deployand Jboss-as-maven-plugin 1.5 does its thing--I can view my app using http://localhost:8080...
just fine, but I want to know where the actual .ear is being put.
It is not in my jboss7.../standalone/deployments folder. So where is it? My app is obviously running in jboss 7.1 just fine, but I can't find the .ear file. I know that there is an .ear in Eclipse's 'target' directory, but that wasn't produced by jboss-as-maven-plugin is it? I hope you can understand my confusion--don't all .ear files need to be in the deployments directory? I also do see my .ear file inside my hidden .m2/repository directory, but does this have any interaction with jboss-as-maven-plugin? Maybe there is some hidden sym-linking between my Eclipse project's 'target' directory and the jboss7.1 standalone/deployment directory?
p.s. I am used to using a hard-deploy option with the other plugin jboss-maven that requires you to say jboss:hard-deploy which just copies the .ear to your deployments folder. Then jboss would pick up the new .ear and redeploy automatically. I get the sense that jboss-as-maven-plugin is the preferred plugin so that's why I am bothering.
The jboss-as-maven-plugin uses the deployment API so it doesn't copy the file to the deployments directory for the scanner to pick it up. It deploys just as if you deployed it from the web console or via CLI. The files should be located somewhere in the $JBOSS_HOME/standalone/data/ directory.
You're welcome to open an issue, for a discussion around it at least. I'm not sure how I feel about adding a goal for it, but here isn't the place to discuss that :)

TOMCAT 7 not deploying war

I have developed a Dynamic Java Project with Eclipse which involves web services(RESTful). After completion I tried to run my project Tomcat 7 runtime of Eclipse IDE, it works fine. I am able to access all my web services.
But, when I created a WAR file out of my project by right-clicking on project and exporting it to WAR file and placed .war file in Tomcat 7's webapps folder. Started the tomcat by running startup.bat, it throws below exceptions and I am not able t access any web service:
I have placed all the required jar files in lib folder of Tomcat.
Exception fixing docBase for context [/Books] (Books is my war file name)
Failed to create work directory [{CATALINA_HOME}\work\Catalina\localhost\Books]
Failed to create destination directory to copy resources.
Could anyone please let me know what I am missing??
Thanks in advance.
Regards,
Piyush
The failed to create "work directory" error can occur if the work folder does not exist in the tomcat7 folder.
Also this error can be caused by tomcat not having sufficient permissions to read, write and execute in the tomcat7 directory.
The issue is because, tomcat is not finding your web.xml location in the classpath.
Do below steps:
Right click on web project-->Properties-->Deployment Assembly--> Add your classpath to web.xml(src/main/webapp) in my case.

Resources