What i mean by this question is that can people start a .jar application embedded on web or they have to download it ? I made a simple online game and people nowadays will not want to individually download the game instead of directly accessing it through the browser. I developed the game on desktop, which steps should i take to make it a web application, or can it directly be converted to a web application ?
If you don't want the user to download the entire application then you must recode it using web technologies.
If you want your answers be able to launch the application via their browse (which involve the download of the application "transparently") you can just make an Applet like #huseyin tugrul buyukisik said or you can use Java Web Start : http://docs.oracle.com/javase/tutorial/deployment/webstart/
You can wrap your classes in an applet, just add a button to launch the class.
init() method will be overloaded to load the classes, start() method is to launch things. Applet is single thread so if you launch expensive loop in one of the overloaded methods, applet can stuck. You can need threads.
There is no direct conversion from jar to web application. Web servers wouldn't understand this. what you need is to
create a web application folder structure, copy jar to web-inf\lib folder
prepare web.xml as required for your application
bundle web application folder into a war file or deploy it exploded
Typical web application folder looks like:
webapp
|-*.html,*.images, *.js, *.css
|-WEB-INF
|-WEB-INF/web.xml
|-WEB-INF/lib/*.jar
|-WEB-INF/classes/*.class, *.properties
The major change in this scenario IMO would be change in routing of request to web-server instead of approach taken by your desktop app i.e. single JVM, calls directly routed to handler class instance.
Say a hypothetical case, upon save from a GUI the desktop app might be serializing data to local disk, now in case of web application it might be required to send this data to web-server (say specific SaveServlet) which takes care of this logic at server machine instead of clients.
If you provide specific usecase of your desktop app functionality, we might be able to help better.
you can do this using jnlp (java native language plugin), which will be download automatically when user visits your page (even by providing link for the same).
After that it will ask user permission to execute that jnlp (same as a jar) & your jar will be executed at the client side.
http://www.mkyong.com/java/java-web-start-jnlp-tutorial-unofficial-guide/
Related
I am new to Java EE.
I have a Standalone maven project which I need to make war deployable project. It contains many servlets & embedded-Jetty is used to run them.
Step which I have done:
Made a new Maven project with archtype-webapp.
Copy all the servlets and other classes in src/main/java
Added those servlets to web.xml
The original project contains a main which sets up the jetty server and does a initial login check and initializes all the servlets.
Can someone explain what exactly happens when we run a program as run on server.
What gets executed first (like main in standalone program).
Here is quick list of what happens-
As you open the url, e.g. http://localhost:8080/AppName, the file mentioned in the welcome file is served in the browser.
You can have an HTML form here with fields for login id and password, and the url in the of the servlet which will be invoked when the form is submitted.
Your servlet would be invoked and from thereon you can do whatever you want, call whatever class you want to call.
This is the most basic form, you might want to start with a simple web application to understand the basics before you start converting your application. That will allow you to understand the flow and then adapt your code accordingly.
Hope this helps.
I have a web application built on the JVM. In this application the users are able to upload files. I read the contents of the file and do "something" with it.
In addition to this, I would like to give option to the users to put in a directory path. This directory path will be read by the application and the directory will be scanned for all relevant files (.CSV). And each will be processed.
Questions
Will the web-application be able to scan the directory located on the users machine? Or the directory path need to be in a network to which the web-app has access to?
I will be using the Commons IO package to scan the directory for files and process the files, is there a better approach?
You cannot access file system of user machine from pure web application. This task can be implemented using trusted applet or java application executed via java web start or trusted flash component or other native component (browser plugin).
Applets are almost obsolete and require JVM on client side. Java web start still requires JVM. All signed components (java based, flash, native code) require user approval.
I think that better and more modern way is to use a great feature of HTML 5 that allows not navigation to specific location on disk (that was possible since HTML 1.0) but also selecting a full directory.
Take a look on the following discussion for details: Does HTML5 allow drag-drop upload of folders or a folder tree?
I have a Web Project which is running on Tomcat7.
When a user uploads a pdf file I want to pass it to another Java Project which can be called by command line (not written by me but by Apache).
Since the Web Project itself is quite huge, I do not want to include the other Java Project inside the Web Project.
Also logically it makes sense to keep the Projects separate.
This is how the flow works - User uploads a pdf file. This is passed to the Web Projects Business Layer. . After getting the details of the pdf from the "other" project I want to save it in the DB via the Web Projects DAO layer.
Can you suggest ways to call the method of another Project?
You can create a wrapper for this command line tool and host it as service. It will be easier for your webcomponent to deal with service. Also all the exception scenario can be handled by service making it easier for your webproject
You can write a shell script and call it from your webproject to invoke another project
Runtime.getRuntime().exec("script.sh");
I have developed a command-line (read: no GUI) Java application which crunches through numbers based on a given dataset and a series of parameters; and spits out a series of HTML files as resultant reports. These reports hold a large amount of data in tables, so in order to give the users a easy and quick overview of the results, I utilized the JUNG2 library and created a nice graph.
Here's where it gets interesting; since I would like the graph to be interactive it should be deployed after the application has run and files are generated, whenever the user wants to view the reports. I decided to go with an applet based deployment, however I am not too happy with the current setup due to the following reasons:
I want to make the software as simple to use as possible (my users won't be tech-savvy, and even tech-intimidated in most cases). I would really like to distribute one JAR only, which forced me to put the applet with everything else it needs in a package in the same JAR as the main application.
The applet and the main application need to communicate the results, so I create a xML-based report which is used to hold information. As long as the files are on a local machine and are not moved around it all works fine. Unfortunately I also need the files to be moved around. A user should be able to take the "results" folder to a USB stick, go anywhere plug the stick to another computer and be able to use the report as he/she likes.
For the time being the applets are implemented with the following html code:
<applet code="package.myapp.visualization.GraphApplet.class"
codebase="file:/home/user/myApp"
archive="myApp-0.2.6-r28.jar"
width="750" height="750">
<param name=input value="results/test_name/results.fxml">
</applet>
As you can see this applet will not work if the parent folder is moved to another location.
As far as I know I have a couple of alternatives:
a) Change codebase to point to an URL on our webserver where I could put the jar file. This however creates the problem with permissions, as the applet will not be able to read the results file. Alternative is to upload the results file to the server when the user wants to visualize the graph, although I am not sure if that's a good option due to server security and also if it could be made so that upload happens automatically without bothering the user.
b) I can use a relative path on the codebase attribute, but then the whole folder hierarchy needs to be intact upon copy. This could be a last resort, if I cant come up with a better way to do it.
c) change the deployment method (would like to avoid this alternative to not spend more time on the development phase)
Any ideas? Am I missing something? How could I tackle this problem?
Thanks,
I'm not sure I entirely understand your use-case, but from what I do understand, I would suggest this:
Dump the applet for an application launched using Java Web Start. Have the JNLP file declare a file association for the fxml file type. When the user double clicks an fxml file, it will be passed as an argument to the main(String[]) of the JWS application.
A sand-boxed JWS application can gain access to resources on the local file system using the JNLP API. Here is my demo. of the JNLP API file services.
i have a java based web application, i have the source code as well as the war file, the application uses mySql and need some web server like tomcat all to be added to some package that can be directly installed on window and linux machines directly..
i need to setup DB, WebServer, and app in one go. Would be great if it can create services for all as well.
is it possible???
i mean the user should just give the location to store and everything should get stored in one go, is it feasible? and if yes please guide me how to do so...
In short: Yes, it is.
Projects like XAMPP are already following that approach. All relevant software components are inside a single ZIP file which you can extract to an arbitrary location on the user's harddisk. All configuration then uses relative paths when referencing files.
So essentially, you will have to put in a little effort in advance to make the "installation" as easy as possible. Maybe you can simply build upon a project like XAMPP and use the infrastructure already provided?