I have no idea if it is possible but I heard that the best practice is to create a frontend project and a backend project as two independence projects. To do that, I should use Nginx, right? But how exactly do that and how exactly is it works?
I just create an angular2 project with node.js and start the server to listen to for example 80 port.
Then I create a java project with jetty and start the server to listen to for example 90 port.
Then, should I in some way create Nginx project to merge frontend and backend? I need help cause I'm afraid I can't understant how to do that.
It looks like you're mixing up a few things here:
In general it would make sense that your project is either written in JavaScript, and is running in Node.js, or written in Java (or a JVM language) as a Servlet, in which case it will run inside a Servlet Container like Jetty or Tomcat.
A web server like nginx or Apache httpd can be placed in front of the backend service in order to handle static content, provide caching, security, load balancing etc.
Related
I'm thinking about what might be the best solution to create a standalone client-server application in java with these features:
Server: it must provide APIs (probably rest?)
Client: javafx webview with angularjs to make requests to webserver.
Loader; it starts the server and the client;
The user can then manage the application directly from the webview or from the browser (to the server port)
This would also be able to create in the future a "cloud" version of the application, the client instead to query the localhost will perform to a remote server.
A solution of this type is correct?
What might be useful tools for its realization and how could it be structured?
I would like in particular a solution which does not require the use of a large Java Application Server, but something more simple that it can be included as a library.
I thought same architecture which you think because it's easy. localhost binding, angularjs, bootstrap in java Webview. one of solutions is Spring MVC Rest API with embedded tomcat. it may be not lightweight.
I want to develop a standalone java application, with web browser as front end. This application will run locally and won't be making any remote server calls. I'm essentially using java, as web-browser cannot perform file operations.
I want this application to be portable: no need of installation. Just copying a folder should be enough. I want to know how it can be done, how will javascript communicate with java code.
In continuation of #Quentin's answer.
Yes, you need web server.
There are 2 principal architectures:
Create stand alone application with embedded web server
Create ordinary web application and run it on proprietary web server.
IMHO I think that the second approach is better, however it strongly depend on your application functionality.
You can take jetty or grizzly as a web container. Both can run as in embedded or stand alone modes. You are welcome to share other details of your application with the community if you need concrete advises concerning to the design of your application.
The application would need to implement an HTTP server. Then all communication would be done over HTTP.
Write a small web application as you need and Deploy it using Jetty. Jetty is a pure Java-based HTTP server and Java Servlet container. You can use it by embedded mode also.
Deployment is so easy if you use Jetty-Runner
java -jar jetty-runner.jar my.war
You don't need a local web server. Take JavaFX (embedded webkit) and implement a URL protocol handler for say "myprotocol". Then you can access it from the browser using something myprotocol://xxx.yyy.zzz
I'm studying webservices in differents languages and now, I'm stuck on Netbeans one.
I easily create a "RESTful web service with Database" on localhost.
So, I use a MySQL (Connector/J driver) connection with GlassFish server.
My question is : what's the difference between an Apache server and a GlassFish one ?
Indeed, I aim to deploy this webservice on Apache server but I have no idea to do it.
Is someone have tips or ways to help me ?
Thanks a lot !
I'm assuming you followed this tutorial.
If you mean good old trusty Apache httpd, you won't be able to deploy the project you created to that server, what you create is a Java Enterprise application (and more specifically a WAR, a Webapplication ARchive), and you will need a server capable of deploying that type of applications - like of course Glassfish, but also Apache Tomcat, jetty or any of the Java Enterprise Edition servers
Still assuming that you're talking about Apache httpd, that one and Glassfish are entirely different beasts that serve different purposes, Glassfish is indeed capable of serving up content over http but it contains much more functionality than that, see the above Wikipedia link on Java EE for more links and pointers.
EDIT: you cannot run a servlet container like Tomcat or a Java EE server like GlassFish "inside" an Apache server like you would run php "inside" Apache with mod_php, but it's quite easy to run them alongside each other, where the Apache httpd server is the one that faces outward and basically forwards calls to the backend Java server. There are several techniques to achieve this result, the most popular is probably using mod_jk as explained here for Tomcat and here for Glassfish. Alternatively you could setup mod_proxy, a comparison of these two scenarios here on SO.
Anyways, it's not always necessary to front a Tomcat or Glassfish with an Apache but it may be needed e.g. if the website is serving hybrid content partially written in php or another apache-hosted scripting language or useful to avoid using the servlet container to serve up massive quantities of static content, often not their strongest point. For many applications it's perfectly OK to have a Tomcat or a Glassfish serve up all content avoiding the extra complications introduced by mod_proxy or mod_jk and the dual management of both servers.
open server.xml file in conf folder of apache tomcat. And check for line
Here you can see port =5051 means apache tomcat is configured in port 5051
Open we browser and type http://localhost:5051
Then click "Tomcat manager"
Enter your usename and password
In the next screen you can see section "WAR file to deploy". Select your web service war file and click deploy
I want to create a simple server application which runs on the desktop, and when I type my ip and port on the web browser, it connects to the server client which then opens a webpage with appropriate displays coded on the server application.
I read online that I need to use servlet and Apache Tomcat to make a webpage using Java.
I am wondering if there are any easier way to make a simple webpage which can contain buttons without using servlet and Apache Tomcat?
For example, I can use sockets to communicate between server and client applications. Could I change this client into typing the ip address and port on the web browser which will display a webpage created and contained in the server application and remove the need for servlet and tomcat? If so, how do I create a button on the server application so that web browser can see the button when connecting to the server application?
Thank you very much.
If I understand you correctly, you want to have a web page, but you don't want to use Tomcat (or any other servlet engine).
Although it is technically possible to write your own little web server (using server sockets etc), but what you're basically doing then is rewriting Tomcat. Writing a good web server is a daunting job, and should not be taken lightly. I think you are underestimating that. Instead, use what is already there. Tomcat is really quite easy get running.
Creating the server piece could be done with raw sockets, but I would look at at an embedded server like Jetty. I think it will save you a lot of time and headache.
http://docs.codehaus.org/display/JETTY/Embedding+Jetty
You should look into Play Framework. It will be easier then implementing Tomcat or Apache.
Version 1.2.4 is stable and feature-complete for Java, version 2.x is focused on Scala and doesn't have all the features of 1.2.4 yet.
You don't have to create a servlet. But, you need something that can parse a jsp page - it could be tomcat or some other server which has the same capabilities as tomcat. Though I am not sure if I understood your question correctly.
I am a little confused about the roles of a java application server and its differences from a web server.
I found many sites explaining the same difference between the two but not to my satisfaction.
So please explain me about the two following cases:-
1)App. Server and its difference with web server:
From these two links:
Difference between an application server and a servlet container?
What is the difference between application server and web server?
web server: It handles everything through http protocol by accepting requests from clients and sending
responses to them with the help of its servlet container(e.g Apache Tomcat)
App. Server: An application server supports the whole of JavaEE like JMS,JPA,RPC etc.
Now what I am confused with is that how can I use a lot of JavaEE APIs like JMS,JPA etc. with my Tomcat
by adding their jar files in my web application ?
Does that mean that if I use an appliation server I don't have to add those jar files?(I don't think so)
2)The roles of an appl. server (This is very important to me)
From Wikipedia
http://en.wikipedia.org/wiki/Application_Server
An application server provides services such as security,transaction support etc.
"The term is often used for web servers which support the JavaEE" -- It sounds like if we add the required jar files of JavaEE APIs a web server becomes an appl. server.What about it.
Now my question is how an application server performs the tasks of security control or transaction management by itself ?
E.g. in my web application using Spring framework I am providing security by using spring-security and transaction management by using #Transactional annotation and all those things you know.
So does the appl. server have anything to do with my security or transaction management or it has its own ways ?
Forgive my ignorance.
Using Spring, you're in fact embedding some kind of Java EE container inside your application. But even when using Spring, if you need JTA support (because you need distributed XA transactions), you'll need to use an additional transaction manager. If you need JMS, you'll need to install an additional JMS broker. If you need connection pooling, you'll need to use an additional connection pool. Sometimes it's as simple as adding additional jars to the classpath and properties or XML files. Sometimes it's harder.
A Java EE app server comes with everything bundled. You have less flexibility, but you don't need to install, configure and make everything work by yourself.
When you use the Java EE framework, that is a specification. So the application server, if it is Java EE compliant, needs to implement this. So once it is implemented the specification, then it will address Security,transaction etc because it is mentioned in the spec. So it is a contract. Whereas, in a web server, it will just pull out your static resource. There is no need for handling other stuff.
In case of the Spring framework, the framework knows how to handle transaction, security etc. So particularly the developer need not look into these aspects which are implemented by the Application Server in the other scenario.
how an application server performs the tasks of security control or transaction management by itself
It is rather the specification that address these issues, not the application server. So, the duty of the app server is to implement these.
So, if your application is Java EE compliant, then these areas will be addressed and the implementation would have been done by the app server.
May be this is oversimplification,
A web server is basically a HTTP server serving contents over http protocol. So a web server is simply about serving the contents over http protocol. A typical example would be Apache web server. This is simply a file server.
Now the question is where does the web server gets the contents from ? Possible sources are
Static contents (the contents like images/css etc) which are not generated on request but statically served.
Dynamic contents: Simply put, the contents to be served are generated upon the user request.
For the static contents, the web server does not need anything as it simply reads the file and serves it.
For dynamic contents, the web server might need help of additional components which will generate the contents to be served.
Here the Application Server comes into picture.
Now these additional components referred earlier, might interact with database or some other system etc.
In a web environment where your website is exposed to huge number of users (intended/unintended), you need typical services like transaction/security/concurrency etc. so that the user get expected responses and do not see inconsistencies in the behavior of the application.
An application server has inbuilt abilities to manage transaction/security/concurrency/resource management. generally these are referred as Managed services and environment offered by them is called Managed Environment where these basic services are managed by the application server and programmer does not have be bother for them.
Application Server needs web servers or we can say Web servers use Application server's services to generate dynamic contents.
For example, JBoss uses Tomcat as inbuilt web server. Whereas web logic has its own web server. Tomcat again can be called as application server (in principle) as it also offers managed environment for servlets (it manages concurrency and instance pool of servlets/JSPs ).
Coming your your example of Spring:
An Application server will come inbuilt with transaction/security etc whether you need it or not. The Spring offers a very nice way handling this. Spring has all these things BUT you use what you need. Not just these, but just a Java Web Sever like Tomcat is sufficient to build a full fledged services that needs an application server.