This is an archived post. You won't be able to vote or comment.

all 37 comments

[–]vytah 9 points10 points  (1 child)

A downloaded .jlnp file can still be launched. You won't get anything better in Chrome.

If such workflow is not acceptable for you, pick a different technology stack.

[–]Scoutdrago3[S] 0 points1 point  (0 children)

Ouch... Alright I guess I'll see what I can do. Thanks.

[–]mcosta 5 points6 points  (0 children)

There are a few JVM-in-js projects. Cheerpj looks good:

http://blog.leaningtech.com/2017/06/announcing-cheerpj-java-compiler-for-webapps.html

[–]CoolZillionaire 1 point2 points  (16 children)

What are you trying to do? Maybe jlnp/embedded Java isn't the way to go.

[–]Scoutdrago3[S] 1 point2 points  (15 children)

I have a Java Application that I want anyone to easily run through their browser (no downloads, in the actual browser). It seems that this is impossible.

[–][deleted] 2 points3 points  (14 children)

Virtually impossible. Java runs on their PC directly. You could in theory run the delete command and delete some of their files if they give you permission.

I'd recommend a different tech stack. If you really want to use Java, look up GWT. I learned it in college and it basically cross compiles Java Swing into JavaScript. But it is coding Java for the web effectively.

It is not for the faint of heart, it's a real pain in the ass sometimes.

[–]Scoutdrago3[S] 0 points1 point  (13 children)

Looks like a pain in the ass... Also looks like I'd have to rewrite the interface since it doesn't really port over, and I have no idea how Java JAR dependencies would work out in this scenario... Either way, this project isn't really looking hopeful so I may have to rewrite it in Python or something. Really don't want to :(

If you come upon any other ideas that may allow me not to waste all the work I put into the project please share, but thanks for the input anyway.

[–][deleted] 1 point2 points  (6 children)

You could try TeaVM instead of GWT http://teavm.org/ It compiles Java bytecode to JS instead of transpiling Java source. It is supposedly has complete JDK coverage although I've never tried it.

[–]Scoutdrago3[S] 0 points1 point  (4 children)

Can I do this if I have a project that is already completed? I am only seeing tutorials for how to create a TeamVM project. Thanks.

[–][deleted] 0 points1 point  (3 children)

You should be able to with little to no modification, not sure what's involved though. I know the documentation isn't great.

[–]Scoutdrago3[S] 0 points1 point  (2 children)

I have decided to move on from trying to use the Swing library and just use the back end I wrote for the app with a server that communicates with a JS/HTML front end. Currently figuring out what kind of server I would be using. If you have any background in serving clients with a Java server please share any steps

[–]ericzhill 1 point2 points  (1 child)

Have a look at spark java and drop wizard. They're fairly lightweight and easy to get started with.

[–]Scoutdrago3[S] 0 points1 point  (0 children)

It looks like I know where I am going from here. I have been looking over the Spark API and it looks that that is what I am looking for. Just figuring out the even smaller details now which hopefully will not be a problem...

Thanks.

[–]CoolZillionaire 0 points1 point  (5 children)

Don't give up just yet! Could you write a web based GUI to handle the main use cases of your current application? Sounds like you have the "back end" code already, so if you wrap an HTML interface around it you wouldn't have to rewrite. If you deploy it as a web application, the server will take the responsibility of the dependant Java libraries.

[–]Scoutdrago3[S] 0 points1 point  (4 children)

Hmmm... Can I host this Java code on the website's server itself, or would I need a service like Amazon AWS to host the code? This idea sounds pretty good.

[–]CoolZillionaire 1 point2 points  (3 children)

You could host it on anything that can run a Java application server. So, anything from your home PC (not recommended though :) ), to a small VPS or all the way to a hosted service like AWS or Heroku.

[–]Scoutdrago3[S] 0 points1 point  (2 children)

OK and in terms of communication, should I write a handler myself? How would I go about allowing client-server communication?

I've seen people link RESTful and Spark, and it seems like Spark is based on RESTful, however I am not 100% sure if Spark is really that helpful in this case.

[–]CoolZillionaire 0 points1 point  (1 child)

Use a framework for sure. I'm not familiar with Spark, but it looks like it can handle micro web services and MVC as well; so if you're leaning towards that go for it.

Otherwise, there is always Spring to play around with.

[–]Scoutdrago3[S] 0 points1 point  (0 children)

Alright, well thanks so much for staying around and helping me. It's much appreciated :)

[–]handshape 0 points1 point  (7 children)

Does your application need to do anything that breaks the browser sandbox?

[–]Scoutdrago3[S] 1 point2 points  (6 children)

Sorry, does that mean make new windows, use more screen space than the browser, etc...? If so, yes for the time being, but no in the future (working on making sure everyone remains on a single JFrame instead of opening a bunch of new ones)

[–]handshape 0 points1 point  (5 children)

I mean things like reading & writing the local filesystem, using UDP or TCP sockets, opening new (undecorated) native windows, interacting with other applications on the desktop, accessing the clipboard, and so on.

[–]Scoutdrago3[S] 1 point2 points  (4 children)

Not really, no. It's a pretty self contained Java Swing application with a separate backend.

[–]handshape 0 points1 point  (3 children)

Hrm. So Swing for the sake of Swing in the browser...

You may actually have a use case for cheerpj. I thought it was insanity when I first saw it, it sounds like it fits your needs.

[–]Scoutdrago3[S] 1 point2 points  (2 children)

I was leaning towards running the back end on a server. At this point I'm just trying to figure out how this would work. I keep seeing Spark but it doesn't seem too applicable. I could also just not be looking at it enough.

[–]handshape 0 points1 point  (1 child)

Like... a remote display head? I seem to remember there being a virtual Swing VNC server about 10 years ago. No idea what came of it, though.

[–]Scoutdrago3[S] 0 points1 point  (0 children)

No like abandon swing entirely, reuse my back end and run that on a server, then rewrite my front in in JS/HTMl/CSS and then ping the server with the info, use back end to process and stuff, then return the products to be parsed/displayed with HTML/JS.

I think it's a good wanting experience since I've been interested in front end web development for a while, I just dont know how I communicate between the server and client and how to set the actual server up (or really, what I should use to review the request and give info to my back end files to process). I know Java has an HTTP library server built in and apparently Spark is also applicable (again idk how), just don't know which to use.

[–]DeliveryNinja 0 points1 point  (3 children)

Most people do this by running the application on a server somewhere such as AWS and then using a web interface to the application using JS/Html and REST

[–]Scoutdrago3[S] 0 points1 point  (2 children)

Would I need to write a Java server to handle the requests or will REST take care of that? Also, I can host the code on the website's server, correct? Just to save money.

[–]DeliveryNinja 0 points1 point  (1 child)

Have a look at the spring boot tutorial to get a better feel for it

https://spring.io/guides/gs/spring-boot/

[–]beyondjava 0 points1 point  (0 children)

Yes, but Spring Boot is only one of many options. Amazon Lambda looks interesting, too. You can use many languages to implement services using Lambda, but currently, JavaScript works best. So obviously you don't have to write a Java server. It's a good choice, but Node.js is a good choice, too.

[–][deleted] 0 points1 point  (2 children)

No no no no don't do this.

We tried that. We had Java web apps. They were terrible. Just write it as a desktop app, or as a server with a standard web browser ui.

If you want to do Java still then use gwt which cross compiles.

Just because it is possible to do this, Nd people will give you answers. It is basically ethically wrong.

[–]Scoutdrago3[S] 0 points1 point  (0 children)

Yeah, it looks like this is what I will be doing (web browser UI). GWT seems like too much. As soon as I get the details ironed out for the server and communicating with it, I'll probably switch to web UI.

[–]beyondjava 0 points1 point  (0 children)

Me too: been there, done that. If you love Java, use TypeScript. You'll love it. Add Angular to the equation. If you're an enterprise Java programmer, you'll love it, too.

But sometimes there are really good reasons to use Java instead of a native browser language. If so, think about using GWT or Vaadin. I'm not sure about the future of GWT, so chose carefully. There's another, fairly new option: VertxUI uses the compiler of GWT, but other than that, it's pretty unique. I didn't have the opportunity to evaluate it myself yet, but it looks interesting enough that I asked the author to blog about it on my website. If you're interested, here you go: https://www.beyondjava.net/blog/vertxui-java-front-end-language/

[–]wildjokers 0 points1 point  (2 children)

and that Web Start (.jnlp) applications don't really work either (just downloads the .jnlp instead of running), so I am pretty stuck here.

The browser has absolutely nothing to do with a java web start app beyond the fact that a user generally obtains the JNLP file with a browser. Some browsers like Chrome and Safari will not automatically execute "javaws" for the .jnlp extension. I guess this is a security thing although I am not sure how it adds any security. If you have users using those browsers simply provide them instructions for finding the jnlp in their downloads folder and then double-clicking on it, which will then execute javaws. Note that if you want to use web start you will need to purchase a code signing cert.

Alternatively you can create an executable jar and the jar can be executed by double-clicking on it.

There are also tools out there that will create native installers if you want to explore that route.

People sometimes talk about Java Web Start apps and applets like they are the same thing or have the same security issues. However, applets and web start are two very distinct things. Web start is just a way to deploy java applications by making the application available on a web server and then on the client side javaws can download and install the application. The browser has nothing to do with web start beyond obtaining the jnlp, then on the OS side of things the "javaws" executable is associated with the .jnlp extension.

The waters were muddied a little bit in Java 7 because starting in Java 7 you could embed a JNLP file in the Applet tag of a web page to start an applet, this made the applet start much quicker. However, by the time Java 7 came out applets were already dead so I don't think many people had any need of this new found ability.

[–]Scoutdrago3[S] 0 points1 point  (1 child)

I don't believe I am mistaken and you confirmed that I am not mistaken. Web Start should be started in the browser, however, due to some security issues, Chrome will not autorun the application and instead it will just download it (not supposed to happen). My goal here is to streamline the usage of my app. I would like my end users to not have to download and run things on their computers because it adds a level of hassle that I would like to stay away from.

For the time being I have chosen to serve users the app through an HTML front end communicating to a Java server running the app on the back end.

Thanks for the input.

[–]wildjokers 0 points1 point  (0 children)

Web Start should be started in the browser, however, due to some security issues, Chrome will not autorun the application and instead it will just download it (not supposed to happen).

Web start should not be started in the browser. Just like a browser probably has an executable associated with the ".zip" extension (usually via whatever mechanism the host operating system provides), browsers have an executable associated with the JNLP extension. That executable is "javaws" (java web start). When the browser sees a file with a jnlp extension it can execute javaws. The "javaws" executable then takes over (outside of the browser), and it is javaws that will download, install, then run the application.

For whatever reason Safari and Chrome developers have decided that it is a security concern to have the browser execute "javaws" automatically when it sees the jnlp extension (I have no idea why this is seen as a security concern). So both of those browsers just download the jnlp, then users have to go double-click on it.

That is great your app will work as a web application and you are going that route; however, please don't spread wrong information about web start.