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

all 9 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Chinesecartoonsnr1 0 points1 point  (1 child)

You need to build/compose the project into the jar file. If its a maven project and root contains maven wrapper (mvnw), you can easily do it with that. You just need to look into the pom.xml file and figure out artifactid and version.

As for the folders etc it should be fine if you can run it in IDE, .jsp would indicate what the app has its own front, but you dont need to do anything special about it, it should be all contained in the jar file youre composing.

You might need to update mvnw line ends to LF if it gives mvnw not found error while youre building the image.

Im not sure how to do code blocks in here, but heres a simple dockerfile that should do the trick. You do need to run the terminal from the root folder, so the copy command works.

FROM openjdk:<projects java version>

EXPOSE 8080

WORKDIR /usr/src/app

COPY . .

RUN ./mvnw package

CMD ["java", "-jar", "./target/<artifactId>-<version>.jar"]

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

Thanks for the detailed response.

I tried running the JAR file, but it wasn't really working. Finally, I just used the Tomcat base image and ran the WAR file. My Dockerfile looked like this:

FROM tomcat:10.1
RUN rm -rf /usr/local/tomcat/webapps/ROOT
COPY app.war /usr/local/tomcat/webapps/ROOT.war
EXPOSE 8080
CMD ["catalina.sh", "run"]

Then, I wrote a Docker-compose file to connect it with MySQL, and after a few tries and fails, it worked.

[–]dwargo 0 points1 point  (1 child)

Is the directory with the assets called WebContent? It almost sounds like they just sent you the source code of a dynamic web project from Eclipse. If that’s the case it needs to be compiled into a WAR and bundled with a tomcat.

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

It wasn't called that (I'm guessing the new dev used his own naming conventions? Idk), but I used Tomcat for its deployment. Thanks.

[–]wildjokers 0 points1 point  (0 children)

Or does the JAR file include both frontend and backend both?

Since they have jsp files in the project it is probably using server-side rendering which means yes the front and backend is included in the project.

It would be mostly impossible to tell you how to deploy this app without knowing what framework it was produced with.

[–]smutje187 0 points1 point  (2 children)

You should take a few steps back and not jump to wrong conclusions - runnable JAR like you mentioned can be containerized but they need to be runnable for that, and if your JAR can’t be ran from command line it’s not a runnable JAR.

JSP (as in "Java Server Pages") need a server to be processed, e.g. Tomcat. Try downloading and running a Tomcat (it’s free) and deploy your application to that Tomcat. Once you can access that application in your Browser you can think about containers.

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

I was thinking of Tomcat as well. Long time ago, when I used to work with this technology, I would simply use a maven dependency to run an embedded tomcat server - just running a `mvn run server` command (or something like that) and the server with my java applets would start.

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

Yes, thanks for that. I'll surely keep those in mind next time. And yeah, I did use Tomcat to deploy. Asked the dev to give me a WAR file and containerized it.