Run simple executable jar with boxfuse - java

I want to convert an application that currently runs with docker to boxfuse.
After the maven build, I have these relevant files:
/target/my-app-shaded.jar
/config-dev.yml
The command to run the jar locally would be simply jar -jar target/my-app-shaded.jar server config-dev.yml
What I could figure out is that boxfuse run target/my-app-shaded.jar runs the jar file, but how do I add the config file and the command line arguments?

This seems to be a Dropwizard application. In that case you can simply place your configuration under src/main/resources and pass the arguments like this
boxfuse run target/my-app-shaded.jar "-jvm.main.args=server config-dev.yml"
When executing this at the root of your Maven or Gradle project and using the latest Boxfuse Client (you can simply update with boxfuse -u), you can also simplify this to:
boxfuse run "-jvm.main.args=server config-dev.yml"
As Boxfuse will auto-discover the payload.
Also if you name your config file boxfuse.yml you can simply this even further to:
boxfuse run
More info: https://cloudcaptain.sh/docs/payloads/dropwizard#configuration

Related

How to Install & Deploy a java app (.jsp file) in apache tomcat

I have successfully installed apache tomcat & verified it to be working using the curl command
curl http://localhost:8080/
Tomcat is installed in
/var/lib/tomcat8/
webapps/ROOT/index.html
webapps/ROOT/META-INF
lib
I have received following structure of the java app in a zip file
App/
build.xml
deploy.sh
run.sh
www/
*.jsp files
WEB-INF/lib/*.jar files
I want to install and run this app on my server. How can I do that. Specifically I want to know where to place these folders. Do I need to run any of the deploy or build files. Do i need to install the jar files? If I directly run one of the .jsp files from curl command, it crashes due to missing java class.
Perhaps I am missing something obvious but I am new to java env and could not find it from google.
If you haven't tried it yet, consider using Maven to build your projects.
This will automate and simplify a lot of similar work for you, like creating a .war file and deploying your project to Tomcat. With Maven, you have to set the <packaging>war</packaging> in pom.xml (a project configuration file) and run mvn tomcat7:deploy command.
For details look at the above link to Maven docs or for instance check out this tutorial.
You can also use the Tomcat Manager under (default) http://localhost:8080/manager to deploy the .war file manually.

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.

Running Standalone Jar need to add jar on server to run

I created a spring boot job which relies on properties on the server and I can get it to run like so, no modifying manifest.
/bin/java -Dspring.config.location=/var/tmp/com.jdbc.properties -jar my.jar
and it works. But the application relies upon another jar that is an internal jar that lives under /usr/local/share/jni/foo.jar which I want to add to this mix.
I have tried countless runs trying such things as:
java -cp /usr/local/share/jni/foo.jar -Dspring(picking up original line)
When I start to google this, it takes me on magical tours of running:
'org.springframework.boot.loader.JarLauncher'
or
'org.springframework.boot.loader.PropertiesLauncher'
then mucking with manifest etc.
Spent last 4 hours with no success. Is there a best practice to run a standalone jar that needs to consume remote properties file and an additional jar file? Would like to keep it simple if possible.
If you are using Spring Boot and want to have a Fat-jar that encapsulates all your dependencies, the best way is to add the required Jar as a dependency to your project.
Assuming you are using Maven to build your project, the "foo.jar" needs to be added as a Maven dependency to your project. Then, spring Boot maven plugin will pick up the jar and includes it in your Fat-jar.
Even if the "foo.jar" does not exist in any Maven repo, you still can add it manually to your local Maven repo using the Maven command mvn install:install-file (See Maven doc).
Did you try using foo.jar as a provided dependency within your maven/gradle dependencies and building the project as executable war file?
See spring boot's maven plugin description of building executable war files.
Overall. Run spring boot standalone jar on a Linux server. Additionally read the database properties from a static file on the server, and path in a jar file that adds functionality that only lives on the server. Cannot include in the boot lib.
command line run (will convert to shell) and ran.
/path/to/..openjdk-1.7.0.55.x86_64/bin/java -cp /usr/somewhere/jni/Foo.jar:/path/where/lib/MYBOOTJAR.jar org.springframework.boot.loader.JarLauncher --spring.config.location=/path/to/properties/on/server/com.xxx.yyy.zzz.jdbc.properties
Seems like using the JarLauncher (no modifications to manifest, except excluding the Foo.jar from local)
Hope this helps someone else.

Create install anywhere launcher from executable jar

I have a jar file that is being created by Spring Boot. Application runs smoothly when run by command java -jar. I want to create an install anywhere launcher with this jar file.
What I have tried is to send the Spring Boot main class (PropertiesLauncher). The issue is that calling it like this won't load the nested jars inside my executable jar and also the loader.path doesn't seems to work.
Is there a way to call the executable jar like java -jar from the install anywhere launcher?
I was thinking that another option was to create an install anywhere launcher for a script file and inside have the java -jar call. So another question will be:
How do I create an install anywhere launcher for a script file?
'execute command' step will do the trick:
Use this command line:
java -jar <path.to.jar.file>
Use EXECUTE_STDOUT, EXECUTE_STDERR and EXECUTE_EXITCODE built-in variables to catch errors and parse the jar's execution result.
Important notes:
You'll have to make sure your jar includes all of the dependencies (or at least set the classpath in the command line);
To include the dependencies within your jar using eclipse you can:
Export your project as a 'runnable jar file' and select the
'Extract/Package required libraries into generated JAR' option/s
Use Maven to build the project with dependencies; the
maven-assembly-plugin is required.
The 'execute command' will work for batch/cmd/shell scripts as well, but you'll have to make sure the scripts are extracted to a local folder such as %TEMP% or /tmp before you can use them.
Goodluck

Run Apache CXF Client from command line

I have generated a CXF client (this is my first webservice client) that runs on Eclipse but I don't know how to run it from the command line.
The client was generated using the top-down approach: the java files where created using wsdl2java and WDSL files, then I modified them.
I want to execute it from the command line, but I don't know how to set the classpath or if there is something else to set up. In the properties of the Eclipse project there are some libraries that I don't know how to use from the command line: Apache CXF Library, EAR Libraries, Web App Libraries.
How can I execute an Apache CXF client from the command line? Is there a better way to execute it in the production environment? I have heard about maven, but I haven't used it.
I had similar issues trying to run CXF with embedded & configured jetty, eventually got it working:
In eclipse:
Export - runnable jar file - and select copy required libs in subfolder!
on cmd:
java -jar yourunablejar.jar
my jar is then very small, but program_lib folder is big..
In CXF lib dir there is a WHICH_JARS file telling you which jars to include for what.
Ciao
If you want to execute the client from command line, you have to create a main class or use a library such as Apache Commons Cli : http://commons.apache.org/proper/commons-cli/
Then build a jar and execute it with java.
Ear and webapp librairies are for other kind of deployment.
I finally figured it out. I copied all jars in cxf\lib folder to the same location of my jar. If there are more libraries in the Eclipse properties, copy them as well. Then call "java -cp myjar.jar;.\* my.Class"
The .\* loads all jars in the current directory.

Categories

Resources