Seperate frontend code from Maven, Tomcat, jax-rs, Jersey project - java

I am about to create a backend for a web application with Java servlets for a REST Api only, which should base on
Java 11
Maven
Tomcat 9 (externally to project)
JAX-RS
Jersey
Then I am using Eclipse and I have created a dynamic web project and converted it to a Maven project.
Some problems in the project / folder structure might be caused by this. Here is the structure:
When I let the server run and hit localhost:8080/hello_world I can see the index.html in the browser.
I actually have two question:
Having a real WebContent is wrong, isn't it? I should have a real webapps folder, but the WebContent folder should be virtual (from Eclipse), right?
How can I separate the index.html and or at least all other frontend resources (HTML, CSS, JS (React.js etc. pp.)) to a separate folder for heaving one repository for the Java Web Servcice and another one for the frontend? Is this impossible with this tech stack?

I believe that your web service URL is not complete and you have to check your web.xml url-pattern tag and the Path annotation you have defined for your services.
In order to have a better prospect of Restful web services in Eclipse IDE, I suggest you follow these HelloWorld examples (simple hello world rest service and CRUD web services using jersey) to widen your horizon about some configurations in web.xml in which you have to define your container to your application server and corresponding pom.xml for jersey dependencies.
it is ok to have the WebContent folder in Dynamic Web Applications and there is nothing wrong with your project / folder structure

Related

jersey REST layer for existing project

I'm working on project which has an existing war file containing java code. Currently this project is deployed on tomcat but war is not placed in webapps, it is in different location and referenced in tomcat using file containing following in Catalina/localhost folder.
<Context docBase="war path/<file.war>" unPackWAR="false"/>
My requirement is to design a restful webservices for this existing project. I have setup a standalone dynamic web project with Jersey REST setup and its working fine. Whenever a rest call will be made it needs to call its underlying api(existing one).
Note: Both the projects are deployed on same tomcat container, but existing war project file is un-extracted and resides in different location.
Also i dont want to combine both the project into single war.
Could some help me figure out how to call the existing java functions from new REST project?
Can JMX connection work in this case or is that recommended?
Appreciate your help!
Thanks,

How to build web.xml for Dropwizard application

I have created application in Dropwizard, which is serving REST API to my clients. I used to run this from .jar file on server, everything worked fine.
Now I have requirement to move my application to WildFly, so now I assume that I need to have a WAR instead of JAR, and here comes my problem:
How to write web.xml to my application? What to include in there? Could anyone give me any template or tutorial or some example how it is done in Dropwizard?
I found what I was looking for. It's wizard-in-a-box project that do all the necessary things to build a WAR file.

Spring boot web app load new web pages created by another application

I have a webapp that runs with Spring Boot.
It exposes a REST API and some static web pages with AngularJS.
My problem is that I have another application that creates dynamically some other static web pages in the same location of the first web pages but with subfolders.
It works well but when I want to access them throught my browser, the pages aren't displayed...
To illustrate, here is the structure at the begining:
webapp
index.html
And then:
webapp
index.html
directory
directory2
myPage.html
How to do tell Tomcat It has to refresh its structure?
I think this is a very strange project structure. you have several possibilities, the first one of them is to store generated pages not in tomcat webapp but outside of tomcat, somewhere in the filesystem where tomcat has access.
Other variant is to store all needed resources in database.
The last is to use tomcat hot relaod.

Difference between an Enterprise application project and a Web project application in Netbeans IDE

Please I would like to know the major difference between a Jave EE project and a Java Web project in netbeans IDE with respect to the EJB. In fact you can create a web application based on EJB, JPA and JavaServer Faces in Netbeans IDE if you choose the Java Web category.
On the other hand you choose the project category as Jave EE project, NetBeans IDE will create 3 sub-projects, e.g: StoreApp (Enterprise Application project), StoreApp-ejb (EJB project), and StoreApp-war (Web project).
The first one will be packaged as a single .war file, the second one will be packaged as an .ear file, containing the web .war and the EJB .jar.
The difference between these is a bit broad to handle here, but I wouldn't advise on creating EARs unless you know that you want/need to.
I think you should learn firstly about web server and a application server..
well i'll happy to help you.
1) we cannot run enterprise application in web server.. i.e. if u are using EJB etc. to run this EJB project you have to use Application Server like JBoss and many more.
2) while using web server it cannot load any heavy application means if your application having multiple users , in that case connection pooling will come into the picture. for connection pooling Application server much better then web server.
For more you can visit below link:-
What is the difference between application server and web server?
I hope it'll helps you
Thanks!!!
There are 3 kinds of project/application:
Standalone Java application and sometimes call it as swing application. Bundle it in the form of Jar and you can run this application without any web or application server.
Web-application: Basically we have to create a war which is combined with html/jsp,jar etc. This war file has to deployed into webcontainer.
Enterprise Application: We have to create a EAR file which is combined with war, EJB & jar. This has to deployed into application server.
A very helpful tutorial https://www.youtube.com/watch?v=6vMB3rzN_Xw
Hope this helpes... cheers!!!

An address of a website deployed using Tomcat and Eclipse

I'm trying to run a website using Tomcat and Eclipse. I created a Dynamic Web Project, I configured web.xml file and I also used Maven. In a directory src/main/webapp I put an index.html file. I also made a simple REST service in the same project. So this REST service is working for me (for example, when I put "http://localhost:8080/RESTfulService/rest/item" in an address bar. But what is the address that I should write to get an access to a website I put in a webapp folder? I thought "http://localhost:8080/RESTfulService/" should be working, but it's not.
From what i understand of your setup, try "http://localhost:8080/index.html". Do you have a context path called 'RESTfulService' setup?
Do you have a context element listed in your server.xml? If so, what does it say?

Categories

Resources