0

I have developed a maven java project. Project has main method and its running as an application. I am using intellijidea as IDE and maven. What I want to do is, I want to add html files to the project.When I run project as application, I want to display results in browser. How can I do it?

this is my main method:

public class ChemInformatics {

public static void main(String[] args) throws Exception {
    IterativeStreaming streamTest = new IterativeStreaming();
    String path = ChemInformaticsConstants.smallSdfFilePath;
    long startTime = System.nanoTime();

    streamTest.sdfStreamReaderSecondMethod(path);

    long endTime = System.nanoTime();
    streamTest.trackExecutionTime(startTime, endTime);
}

}

enter image description here

Kaushali de Silva
  • 241
  • 1
  • 3
  • 9
  • So do you want to convert your application into a web application? Or you want instead to add some java code, so that when you run the main class, a browser opens which goes to the "welcome page" of your application? – John Donn Oct 21 '16 at 09:01
  • You need to create a Java Web application, you probably should search for some tutorial of how to create web applications in Java. – David SN Oct 21 '16 at 09:04
  • Thank you for your quick responses.no I do not want to create a web application. I want to run a server with main method and display results in browser. – Kaushali de Silva Oct 21 '16 at 09:06
  • 1
    What you need is `Spring Boot`. I think it will cover your needs. – Paweł Głowacz Oct 21 '16 at 11:24

2 Answers2

0

you need to write a servlet or mvc you can follow the instruction here : https://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm and just write one controller with " return ChemInformatics.main()"

It's just a brief introduction.

Daisy Li
  • 54
  • 6
0

You have to understand that your Java code need to be interpreted as a Servlet. This is why a lot of answer suggest you to make a "Dynamic Web Project".

So you need to run a server, like Tomcat, to deploy a .war of your code on it, and to ensure that your code will be called in your HTML. (Your code need to be accesible from somewhere, this is why run it on a server is mandatory)

If you want to display the result on your HTML page, you should consider using AJAX or create a WebApp. (And of course, an API...)

BTW : This is ugly af, not maintenable, and will take a lot of time.

If you still want don't want to use a server

You need to buy an applet. To ensure that an HTML page can call your app, and that's the point, even in local. I would rather use a GUI. You can host a servlet with embedded webserver com.sun.net.httpserver.HttpServer or Jetty

This question is too OPEN

You need to read some documentations and to add some work you have already tried on the first post if you want a real help.

Aks
  • 395
  • 3
  • 11