create exeutable WAR file springboot without maven/Gradle - java

I have created a simple springboot application with inbuild tomcat which works fine when I am running it as JAVA Application in Eclipse. I tried to export this as a WAR file and tried to run it in Windows command line and also in UNIX box. I tried to execute it like below,
java -jar C:\Users\Iam\Documents\SpringHelloWorld.war main.java.com.controller.SpringBootWebApplication
Error: An unexpected error occurred while trying to open file C:\Users\Iam\Documents\SpringHelloWorld.war
java -cp C:\Users\Iam\Documents\SpringHelloWorld.war main.java.com.controller.SpringBootWebApplication
Error: Could not find or load main class main.java.com.controller.SpringBootWebApplication
I just export it as a WAR file, should i need to define anything before exporting it as WAR in Springboot ( note: i am not using maven or gradle )
Below is my project structure :
enter image description here

Probably it is possible to do this without Maven/Gradle, but I would never take this approach.
Even considering the best case, you will end up re-creating what others have created in the Spring Boot parento pom.xml or in his Gradle equivalent, so why you would waste a lot of time recreating what is already created by someone else? If you really want to know how the war is created, then take a look in Spring Boot parent pom, but you should limit your work to wrap what is ready for production in order to compose your solution.
Also consider that Maven and Gradle are constantly developed and updated, along everything belongs to their ecosystems. If you plan to replace them, then you should be prepared to mantain and develop alone your own build platform, which is a non-trivial effort.
Better include Maven or Gradle, you'll be more productive.

Related

How to build, deploy and run Java application on JBoss WildFly from the command line?

My team is working on a Java application that runs on Jboss WildFly, using Maven to resolve dependencies and Primefaces.
We're using Eclipse to build, deploy and run the server. Eclipse does most of the work, building the WAR file, deploying it to server and running it.
Now we need to create an script that performs all those steps because it has to run on remote server.
.
The steps would be something like this...
1 Run Maven:
$M2_HOME/bin/mvn clean install
2 Build project to a war file
3 Deploy war file into the WildFly deployment folder
$WILDFLY_HOME/bin/jboss-cli.sh --connect --command="deploy --force [PATH_TO_WAR]"
4 Start server
$WILDFLY_HOME/bin/standalone.sh
.
I can perform every step but once the server is running it don't seem to be any changes in the application. I think this is because the WAR file has to be built optimizing it for JBoss. Eclipse has a way to do this when exporting the project. I need to know how to do that from command.
EDIT:
The real problem is that Jboss is not updating the published project when i run it from bash script. I thought it was because i had to build it on a specific way. I was wrong. The build is fine, just running Maven the deploy is done. The thing is that even if i rebuild project and redeploy it, server doesn't seem to notice at all.
I've tried deleting tmp, lib and data folders from standalone folder, and nothing happens. I also deleted standalone/deployed sub files and folders and got the same result.
The only way i achieve the result i'm expecting is getting into Eclipse, go to Servers tab, right click on JBoss Wildfly and click on 'Clean...'. This options seems to clean cache, rebuild and re publish the application in a right way that i don't know. I didn't find any answers on google.
eclipse server clean option
Give a look on Eclipse war export: optimize for a specific server runtime.
Quoting from #Konstantin Komissarchik's answer :
Eclipse itself doesn't do anything with that option. What happens is
dependent on a particular server adapter. Many of the adapters don't
do anything with this option either, but they might in the future.
If a server adapter does support export optimization, it has the
option of displaying custom options beneath that pop-up list of
runtimes, so that's a good cue to use to see if something will
actually happen.
So taking in consideration that in your provided image there is no custom options below Wildfly 9 selection, I am pretty sure that this option does not perform any optimization at your exported war so you can totally omit it in your new build-deploy process.
How can i build the war file from command, knowing it will have to run on Wildfly?
We are also deploying applications for a long time on several versions of Widlfy with the same approach as you are planning to, without the optimization thing. I can ensure you that we have not faced any performance issue.

Running Java program on iSeries on command line

I've created a java program and I'm wanting to run it from the iSeries. I've been able to get it to run from the QSH so I know it compiled and runs fine, but I need to run it from the command line not QSH. The program requires the jsch-0.1.55.jar file for the program to work correctly and I'm not 100% sure how to to call the jar file with the program its referencing to.
I've tried
RUNJVA CLASS(ANL0106J) CLASSPATH('/JAVA/Jars/jsch-0.1.55.jar')
That didn't work. Then I tried
RUNJVA CLASS('/JAVA/Jars.jsch-0.1.55.jar':. ANL0106J) CLASSPATH('/Java/Jars/jsch-0.1.55.jar')
That didn't work either. What am I doing wrong?
Having successfully done this many many times, your last try seems pretty close, but change the CLASS parameter to point to your class file which contains the main method. ANL0106J seems like a pretty weird class name.. Example would be:
CLASS(com.company.test.ApplicationMain)
With the CLASSPATH pointing to the required jars using the full path names. For example:
RUNJVA CLASS(com.company.test.ApplicationMain) CLASSPATH('/test/app.jar:/test/dependency.jar')
To make matters a bit easier, you could even include your dependency in your JAR file by using something like maven or Gradle to create your builds, which can then be configured to generate fat jars. Essentially, those are jars that contain the other JAR files that your application depends on. That way, you can also be pretty sure that your application will continue to work, even after you update a single jar file on your ibm i machine for example. Shadowjar for example is pretty easy to setup using a gradle project which will do this for you. Then it's just a matter of running the bootjar gradle task and using the RUNJVA command, simply pointing to your single JAR. Don't get caught up in dependency management hell, please. Save yourself and future devs by using something like maven or gradle. Gradle/maven can even be used to manage depencencies using a maven repository with a tool such as Sonatype Nexus which can also be hosted locally. If your JAR has a valid manifest, you don't have to do anything else. It would look like this:
RUNJVA CLASS('/test/app.jar')
Especially useful for using CI, which can build the JAR for you from a GIT repository and place the fat jar in the correct path, with you not having to do a single thing. Setting up Jenkins on an as400 isn't that difficult at all using the apache WebSphere application server which is an option that can be used to host WAR files, to put it simply (it can do a lot more than that though :P).
Hell, using only a single jar for the RUNJVA command should also speed up the time it takes to start your application since it only needs to verify a single jar. Just food for thought. Here's the maven entry by the way:
https://mvnrepository.com/artifact/com.jcraft/jsch/0.1.55
On a side note for java/react devs: Yes, fellow Java/react developers, one could use the RUNJVA command to modernize ibm i development to run Spring boot applications! We are successfully running react front end applications using a spring boot backend system, Works extremely fast, as expected :)
(Same answer given to you on Reddit, simply on this platform to make it visible for others that are looking for this on Stackoverflow)

How to update native built JavaFX Application

I am building a JavaFX application in Intellij that will be built and distributed with an .exe installer and will be ran as an exe Application. I have been trying to find a way to allow for remote updates, but I have only found resources that update a jar file by using another jar file hosted on a website. Is there a way to allow for remote updates to a exe JavaFX application? I have though about using update4J, but sadly I have no idea how to implement it, use it, or if it will even work with exe applications. I have tried to use FXLauncher, but I am not able to use JavaFX with maven as an error occurs whenever I try adding maven framework to the project.
I am the developer of update4j.
The framework used to be complex and hard to use, but the last release (1.2.2 at time of writing) significantly simplified things leaving only one pain point, namely, generating a configuration.
So for starters, launch the framework using it's own main method:
# on classpath
$ java -jar update4j-1.2.2.jar
# on modulepath
$ java -p update4j-1.2.2.jar -m org.update4j
And read the output.
Creating the configuration is done using a builder, I'm still documenting it but the class javadoc for Configuration is quite complete.

Deploying a Java fat jar with embedded apache Derby database

I have a desktop Java application that I'm developing that has an embedded Apache Derby database (Link) . Now, when I run the application through my IDE, everything works great and functions as expected. However when I create the fat jar (including all the dependencies), when I launch the application it boots fine, but I get the following error message:
java.sql.SQLSyntaxErrorException: Schema 'TDB' does not exist
To me, this suggests that the schema I have created has not been copied across into my new jar file, but in that case I'm not sure if I'm creating my jar correctly.
What I would like it to do is when I run the package goal of my pom, it will create a new jar, with all of the dependencies included, that I could effectively give to someone else and they could run it as a fully functional desktop application (in the same way I can run it through my IDE, just without the IDE).
Any help would be massively appreciated, I've been banging my head against this one for a few days now.
Stu
The way I see it there are two approaches to this:
You determine the file system location of your database files and make sure it is included in your deployment - this should be do-able from within the IDE
You include a start-up process that check if the database is present, and if not creates the schema on the fly

Deploy java (command line) app using Netbeans / ant

I've finally managed to create a Netbeans project out of an old standalone (not Web-) Java application which consisted only out of single .java sources. Now I have basically two questions regarding Netbeans Subversion interaction and application deployment:
Do you check in all the Netbeans project files into the repository, normally?
If I build the project using Netbeans (or ant) I get a .jar file and some additional jar libraries. In order for the app to run properly on the server, some additional config files and directories (log/ for example) are needed. The application itself is a J2SE application (no frameworks) which runs from the command line on a Linux platform. How would you deploy and install such an application? It would also be nice if I could see what version of app is currently installed (maybe by appending the version number to the installed app path).
Thanks for any tips.
No, not usually. Anything specific to NetBeans (or Eclipse, IntteliJ, etc), I don't check in; try to make it build from the command line with your ant script and produce exactly what you want. The build.xml is something that can be used for other IDEs, or in use with Anthill or CruiseControl for automated builds/continuous integration, so that should be checked in. Check in what is needed to produce/create your artifacts.
You don't specify what type of server, or what exact type of application. Some apps are deployed via JNLP/WebStart to be downloaded by multiple users, and have different rules than something deployed standalone for one user on a server to run with no GUI as a monitoring application. I cannot help you more with that unless you can give some more details about your application, the server environment, etc.
Regarding the config files, how do you access those? Are they static and never going to change (something you can load using a ResourceBundle)? ? You can add them to the jar file to look them up in the ResourceBundle, but it all depends on what you are doing there. If they have to be outside the jar file for modification without recompiling, have them copied with an installer script.
As for directories, must they already exist? Or does the application check for their existence, and create them if necessary? If the app can create them if absent, you have no need to create them. If they need to be there, you could make it part of the install script to create those folders before the jar files are installed.
Version number could be as simple as adding an about box somewhere in the app, and looking up the version string in a config/properties file. It has to be maintained, but at least you would be able to access something that would let you know you have deployed build 9876.5.4.321 (or whatever version numbering scheme you use).
Ideally, you should not tie down your application sources and config to a particular IDE.
Questionwise,
I suggest you do not. Keep you repository structure independent of the IDE
You might have to change your application so that it's structure is very generic and can be edited in any IDE.
Is this a web app? A standalone Java app? If you clarify these, it would be easier to answer your query.
We don't check in the /build or the /dist directories.
We tend to use this structure for our Netbeans projects in SVN:
/project1/
/trunk
/tags/
/1.0
/1.1
/binaries/
/1.0
/1.1
When a change is need we check out the netbeans project from trunk/ and make changes to it and check it back in. Once a release of the project is needed we do an SVN copy of the netbeans project files to the next tag version. We also take a copy of the deployable (JAR or WAR) and place it in the version directory under binaries along with any dependencies and config files.
By doing this we have a clean, versioned deployable that is separate from the source. Are deployables are version in the name - project1-1.0.jar, project1-1.1jar and so on.
I disagree with talonx about keeping your source non-IDE specific - by not storing IDE files in SVN along with you source you are adding extra complication to the checkout, change, checkin, deploy cycle. If you store the IDE project files in SVN you can simply check out the project, fire up the IDE and hit build. You don't have to go through the steps of setting up a new project in the IDE, including the files you SVNed, setting up dependencies etc. It saves time and means all developers are working with the same setup, which reduces errors and discrepancies. The last thing you want is for a developer to check out a project to make a small bug fix and have to spend time having to find dependencies and set stuff up.
To answer question #2 -- who's your consumer for this app?
If it's an internal app and only you (or other developers) are going to be deploying it, then what you have is perfectly all right. Throw in a README file explaining the required directories.
If you're sending it out to a client to install, that's a different question, and you should use an installer. There are a few installers out there that wrap an ant script and your resources, which is a nice approach particularly if you don't need the GUI... just write a simple ant script to put everything in the right place.
Version number is up to you -- naming the JARs isn't a bad idea. I also have a habit of printing out the version number on startup, which can come in handy.

Categories