How to separate JSP from main java project - java

we got existing JAVA web application which contains: GWT module (Administration panel), java servlets with some other services in src path and war folder with JSP's and other static files like: images, css, js.
Web server: Tomcat 7
To build this project we use ant build script. It compiles the project, GWT module and packs it into war file.
Now, I need to separate front-side (JSPs and other static files) from backend (Java servlets and other code on Java) into different git repositories, to allow front-end developers editing it.
The main problem is how to make deployment system on test server. They need to see their changes in real time.
It's impossible to install tomcat and java on each front-developer's machine also they don't know what is Java and how to compile the project, that's why we have test stage with tomcat.

It is really hard to answer this question without knowing the exact architecture and organization matters of the project.
But the fact is, the JSP files are translated and compiled into Servlet during translation stage (back-end side). Therefore, it would be quite hard to isolate JSP files from rest of Java WebApp.
I would consider including part of front-end HTML's into JSP, i.e.:
<c:import url="http://example.com/frontend/somepart.html" />
Though, you can divide the architecture into:
BackEnd side: served by Tomcat7 (Java, Servlets, JSP)
FrontEnd side: served by HTTP WebServer (Apache, nginx, IIS or other) - HTML, CSS, JS
Dynamic parts of the application could be proxied by some url pattern using mod_jk (in Apache) to be handled by Tomcat. It may be accomplished by using GWT in such way (example):
Develop Front-End side
Include empty DIV with an ID.
Attach GWT module in <script> tag.
GWT modules attached to ID.
After module load, every service operation must be proxied to dynamic part. Lets say you backend is under http://example.com/backend so you need to configure the Apache server to serve the content under /backend pattern from Tomcat server.
Let the FrontEnd developers code the front-end (html, css, js files) and make deployments on HTTP server without interferring with Back-End development. BackEnd developers could easily deliver their work into Tomcat servers.
Hope it helped.

Related

Two servers each for HTML and Java Jersey Rest APIs or Single Tomcat Webapp

This is a question to design my dynamic website. It should have a java REST APIs beckend and static HTML view.
Should I keep my HTML content in separate server(like AWS S3) and REST APIs in Tomcat(hosted in a EC3 instance)
OR
Should I keep index.jsp as my starting point of application. Thus making both HTML and JAVA sit together in the same project. And If I do take this option, will I be able to use Angular and Bootstrap with this or not.
Hope you understood the question :)
I will advice to deploy dynamic content on the Tomcat app server and static content (HTML, images, CSS) on Apache web server. I wouldn't keep static content on s3. It being on Apache gives a lot of advantages like - using Apache server you can compress, cache, authenticate, throttle your static content.
The static and dynamic code can be together in the same project and repo. The devops build process can build jar and war and deploy them separately.

Angular 2 Basics - Integration with Spring Boot - Can Angular 2 instance run within a server

I am new to angular 2 and js frameworks so this question is probably going to sound a bit stupid, I have a task at work where I am looking to integrate angular 2 with Spring boot application, I went through couple of tutorials online and found that you can configure the proxy setting for paths inside angular to redirect calls to spring boot application for various paths.
For reference: https://dzone.com/articles/angular-2-and-spring-boot-development-environment
The question I want to ask is that since Angular is a js framework and I thought that it could be completely integrated with any application, like plain old javascript, html and css. In a way that only a single port is required to launch the server and jsp based models can be served through it.
But with Angular2 you need a separate port of its own to do anything. Is that true?
If it is then why it is like that?
If not then can you please direct me to a guide which describes how to integrate it in a way that it would be served through the server?
But with Angular2 you need a separate port of its own to do anything. Is that true?
No, not at all. An Angular application, once built, is just a set of satic files that can be served by any web server, including the one running your spring boot app. Those file aren't "run" on the server. They're just downloaded by the browser.
During development, though, it's much more productive to have a separate web server like the one that Angular CLI starts up, and which watches your source files, rebuilds your application on the fly, and serves it immediately. Since this server can also serve as a proxy to your spring server, you can just pretend your spring server hosts the angular files.
An alternative is to use your angular build tool to build the app to some directory, and configure spring to serve static files from that directory.
In production, you'll simply build the production-ready angular app, integrate the generated files inside the spring boot jar file (inside the static folder, typically), and run the spring boot application as usual.

Glassfish deploy error "Archive type of MyProject.jar was not recognized"

I've created a dynamic web application and i'd like to deploy it with glassfish. I've successed build my sources to MyProject.jar. But when i deployed it, the following error displayed:
remote failure: Archive type of /home/davenlin/MyProject/build/MyProject.jar was not recognized
My project is just a normal Restful application, not ejb application, so i don't know if i must generate a MyProject.war instead of MyProject.jar.
Please help me. Thanks !
Okay, because my comment was rather unexplanatory:
Web applications are handled by application servers or servlet containers.
Both do quiet a lot of work for you and web applications are not comparable to
desktop or standalone java applications. While your standalone applications are deployed as jar - files and then executed by the JVM, web applications are
executed by the container (application server / servlet container).
So this does require your application to provide additional configuration and affords the archive itself to have a different structure.
So even if you are just exposing some web services to build a restful application, your application server will do things for you such as
forwarding requests to the right classes, translate query and post parameters into java - objects accessable by your own classes respectivly your own objects and returning your response to the clients.
The interesting thing about it is:
The additional files in the web - archive are usually xml - files and web - related files such as html, css, js.
So this does not distinguish war's from jar's as you can also package additional resources within a jar.
The basic but now obsolete requirement on a war - file is that it contains
a deployment descriptor (which is again is an xml - file)
to configure your application , its context and the relative url (more concrete : url - patterns) it uses , but as this requirement is obsolete someone may still think that this distinguishing is obsolete, too.

How to use both http server and application server in a java web application

I have some deployment model question for a Java EE web application. Currently we are deploying our web application as a WAR file in Tomcat 6. All the content is packaged with the WAR file including the static content like images, static html pages and so on. But i want to deploy these static content in a HTTP server and use the Application server only for retrieving the dynamic content. How do i split these things? Does any one has done any thing of this sort and have a good deployment model for my scenario. Help will be appreciated.
Is it a good idea to make 2 WAR files one with only static content and deploy that WAR in HTTP server and the rest as a different WAR file and deploy it in the Application server? But this approach will have impact on all the pages where the static content is currently referred and requires code changes which is very cumbersome since our project is Huge and the code based is very very big.
Any strategy and ideas are welcome.
This can be something interesting to do for performance reasons.
You should have separate deployment scripts / deployment files to do this.
Having multiple file/WAR/folder/scripts to deploy for one project is not an issue. We have the same thing when you have to deploy your WAR and to update your database.
I would have a WAR file and a folder with your static content to deploy.
Edit
Deploying the static content in a HTTP server depends on the server.
If you want to use Apache on a Linux server, you have to set up a Virtual Host.
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
DocumentRoot /www/domain
</VirtualHost>
In this example, you have the a virtual host that listens on 80 port, for any IP address and for the server name www.example.com. Then this is redirected to the /www/domain path.
You will find much more examples and configuration options in the documentation.
You can not deploy WAR file into HTTP server. A WAR is used for Java web applications it must be deployed into application server or servlet container (like Tomcat). I don't think that its a good idea to separate static content in a separate web application. If this is one project it should be one web application, besides:
A WAR file has a special folder structure and contains special files
in addition to JSP pages, Java servlets, Java classes, HTML pages etc.
which combined forms a Web Application.
You can hold your static contents in your one application and there is really nothing bad about it.
If your project is very huge and has a lot of files it is no problem, you just need to use the project structure like that, that it should be easily understandable and readable and the application server or servlet container will take care of deploying as many contents as there is.
Up to version 4, Tomcat has been quite slow in serving static content. This is why it was frequently recommended to split dynamic from static content and serve the latter using a regular web server (the book you mentioned was issued in 2002...). Recent Tomcat versions do not face this problem, thus you can IMHO refrain from splitting, which can be a nightmare for both organization and security.
For static resources, you might rather focus on configuring proper caching, so they will not be transferred more often than necessary.

Is there a way to run and execute Java files using HTTP from another PC?

I have installed Java and developed on my laptop. Now I want to access those files from my PC using HTTP. Both machines are on the same network. I'd like to access the page as we do in PHP:
http:// and the path
How can I do it? I can see the files using this url: file://machine-name/login.html, but it's not opening in HTTP, replacing file from the url. Please help
Unlike PHP, in Java you can serve only JSP or Servlets. You will need to have an Application Server - like Tomcat, to deploy your web components. There are many different ways how you can package your web components. Typically all files (JSP, Servlets, Classes) etc. are packaged in a 'war' file. Thiw war file can be deployed to any Java compliant application servers.
Try this URL - Simple Tomcat application
Hope this helps.
Regards,
Sreehari.

Categories