Spring Boot Run Jar file in linux - java

I have developed a Spring Boot Application using Restfull API. The application working perfectly in STS. But now i am trying to run a jar file in linux, any idea.

You can generate runnable jar file using 2 ways.
a. Exporting as JAR file from STS.
Right click on project in STS --> click on Export --> search for jar
--> click on JAR file --> select project --> select resource to export --> Select checkbox : Export Java source files and resources --> select the export destination --> give a name for JAR file (for
example abcd.jar) click finish to generate JAR file.
b. Using Maven.
First, make sure that you have the repackage goal included in your
build setup, then use the Maven package target. The simplest way
to do this is to run mvn package from the command line (you may need
to install the Maven CLI package for your OS); you can also
right-click the POM in Eclipse and "Run As" to execute specific Maven
operations from within Eclipse.
To run JAR file open command/terminal prompt and reach to destination where JAR file was created. then execute command java -jar abcd.jar

Can you follow the steps
check the version which you have installed in Linux
java -version
Install the JDK corresponding to your application version which you have created application
sudo apt-get install openjdk-version-what you want JDK verson -jre
// example - sudo apt-get install openjdk-7-jre
Run the application simply typing
java -jar Minecraft.jar

Related

How to generate jar file from spring boot application using gradle?

I am creating a spring boot application using gradle. I need to create
a jar which include all needed libraries for deploying on (aws) ec2
instance.
I am trying to create a jar by...
1)click on project structure
2)then click on Artifact
3)click on + -> jar -> from modules with dependencies -> select project -> select main class
4)click on ok with default settings
5)click on build tab
6)I got a jar file but it doesn't contain classes.
Use Terminal/Command Prompt to generate jar using Gradle
To generate jar without running test cases
./gradlew build -x test
If you want to run the test cases before creating jar, then
./gradlew build
First make sure you have downloaded gradle and set up in your system variable.
to check this simply run gradle -v in your cmd.
Under System Variables select Path, then click Edit. Add an entry for
C:\Gradle\gradle-6.5.1\bin. Click OK to save.
Now you simply goes to project directory and run
./gradlew build -x test
Now you get your executable jar file

How to export JavaFX gradle project as a standalone executable file for deployment?

I have completed my JavaFX application within gradle build system, and it is working fine in all way. Now I want to export as a .EXE file for standalone software distribution, I tried much more tricks but no gain. If some one can help me out to wrap my project in a software setup, It would be grateful.
Follow these steps to export your JavaFX project into executable Jar
Goto> Project Structure
Goto>>Artifacts
Click "+">> To add new artifact
It will shows a dropdownlist
Select>>Jar>>From module with dependencies
You will see a nested window as shown
Select Main class of your project
Check In the Option " Copy to output directory.." >>Ok
Goto>> Menu-bar>>Build>>Build Artifacts
Select>> your Project.jar>> Build
This will create executable jar file in your project source folder
Locate your jar file in path project\out\artifacts..
Now you can run this jar file simple cmd commad or with batch file
Cmd Command>> Java -jar project.jar
Using batch file>> make .bat file name it "RUN" and write these commands inside
Specify the Java Runtime path and "Javafx Sdk path" along with VM
options & Project Jar
Run your standalone application .. Enjoy ;)
Creating an installer for the desktop platforms (Windows, macOS, Linux) has become easy these days. The tool of choice is jpackage which started to be shipped with JDK 14. It can either be used on the command line on the finished project or you can use a Gradle plugin (https://github.com/beryx/badass-jlink-plugin). If your project is not modularized you could follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which also uses jpackage but together with Maven and some other tools from the JDK. The Maven part could easily be rewritten to Gradle, if needed.

Running a project built in docker in Eclipse

Sorry if I am being ignorant but I am quite confused on
How to run this project in eclipse:
https://github.com/ivanlomba/taboleiro
It was packed with docker and I have no experience with it whatsoever.
If anyone could help me out it would be great!
I'm not an Eclipse user, but It's a Spring Boot application and uses Maven as build tool, so you can import the project (files inside code folder) as "Existing maven project". There are tons of tutorials about creating/importing a Spring Boot project with Eclipse and Maven if you have any doubts.
If you don't use Docker you will need to configure the mysql database manually. You can find the schema of the database inside resources folder.
Docker part is only to deploy. Search for how to set up environment variables in your OS.
get Java 8 or newer, make sure the folder above bin of Java is defined as JAVA_HOME (like if your javac.exe path is "c:\program files\java\java8_121\bin\javac.exe" then JAVA_HOME="c:\program files\java\java8_121" without slash in the end
Download maven, unzip to a folder like c:\apps\maven then add the parent of the bin folder as MAVEN_HOME
like MAVEN_HOME=c:\apps\maven\maven_4_xyz
Change the PATH variable to be
PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%
Now in termimal cd to the code folder of where you have cloned or unzipped https://github.com/ivanlomba/taboleiro/tree/master/code then give the commands
mvn install
mvn test
Now in IDE install maven plugin too if its not there, then can import as an existing maven project.
If your in linux change the paths to
MAVEN_HOME=/path/maven_4_xyz
and
export PATH=$JAVA_HOME/bin:$GRADLE_HOME/bin:$MVN_HOME/bin:$PATH
in ~/.profile or other place

Running spring boot app after teamcity build and deploy

Is there another way to run deployed spring boot application on server than *sh script?
My idea is create .sh script which will start app (java -jar name...). This solution is simple but have one disadvantage - I have application version in the file name. I can trust that there will be only one *jar file and run it - but I am not sure that it is best solution.
What do you think?
You could use maven-assembly-plugin to bundle your application jar and sh script onto one zip file. In this case you could use maven resource filtering to put replace ${version} placeholder in your sh with exact version of your jar during maven build.
If your jar has name like this: `my-project-.jar1 then your sh script will look like this:
java -jar my-project-${version}.jar
During build maven will replace ${version} with value from pom.xml.
So after build you need to unpack zip (or tar.gz) and execute sh script.

Exporting Spring Boot application as JAR file in eclipse

I'm using the Spring STS in Eclipse to create a simple web-based spring boot project. I can run it fine in Eclipse, but when I try to export it as a JAR file I get:
rg.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
My public static void mainis located in Application.java, with the #SpringBootApplication annotation.
I've double checked all the Maven dependencies a hundred times.
What am I doing wrong?
Most likely, you're using the built-in Eclipse exporter to generate your jar, which only includes the target files actually produced in that project. In order to have a "fat" (standalone executable) jar, you need to use the Spring Boot Maven or Gradle plugin to "repackage" the jar.
First, make sure that you have the repackage goal included in your build setup, then use the Maven package target. The simplest way to do this is to run mvn package from the command line (you may need to install the Maven CLI package for your OS); you can also right-click the POM in Eclipse and "Run As" to execute specific Maven operations from within Eclipse.
It is a single line command, on window 7/10 machine, with command prompt to your project folder (Inside your project workspace). I do not do with Eclipse IDE POM maven goals, but you can do with maven goal there also. ON window machine I prefer cmd.exe for exporting and running.
mvnw clean package
on unix kernel based
./mvnw clean package
You have to go inside workspace and than to the project root folder. You will see a maven wrapper mvnw, with that you don't need to have maven installed and .mvn folder at the same level provides necessary jar for that.
For a project
D:\workspace\Zuteller Workspace\zusteller>mvnw clean package
it will create zusteller-0.0.1-SNAPSHOT.jar in the target folder at the same level.
D:\workspace\Zuteller Workspace\zusteller>java -jar target\zusteller-0.0.1-SNAPSHOT.jar
You can run self-contained application(embedded Tomcat) and access at localhost:8080/your project

Categories

Resources