I have a (large) maven-web-project with many dependencies. The project runs an embedded jetty.
For some (customer related) reasons I cannot package a war to deploy it to some application server like a standalone jetty or tomcat.
Now I need to deploy the whole project with all dependencies-jars and the web-root stuff to some production-server, where I can start by command line the embedded jetty like java -jar myproject.jar.
How can I build such a package with maven. I tried maven-assembly-plugin, but I do not want to re-pack jars. (IMHO this is not a really good idea.)
I need to package some zip or tar like:
myproject.zip
--myproject.jar
--META-INF (with the whole classpath and may be the auto-start class)
--libs
--slf4j.jar
--logback.jar
--hibernate.jar
--and many, many more.
Any ideas? TIA!
If you use Spring you can use Spring Boot which does this by default. By using Spring Boot maven plugin it will build you a uber jar containing all your dependencies and an embed tomcat or jetty.
Related
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.
I have an application built using maven and spring mvc and tomcat7-maven-plugin. Can I package these to a jar file, so that i can run the jar file to start a tomcat server?
That means i don't need tomcat, only a jar file can provide a web service.
Spring documentation is your friend. I am providing the links which you can follow, with highlighted parts in this post.
Spring Boot Maven Packaging
Once spring-boot-maven-plugin has been included in your pom.xml it will automatically attempt to rewrite archives to make them executable using the spring-boot:repackage goal. You should configure your project to build a jar or war (as appropriate) using the usual packaging element in the pom.xml
The main class that you want to launch can either be specified using a configuration option, or by adding a Main-Class attribute to the manifest in the usual way.
To build and run a project artifact, you can type the following:
$ mvn package
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar
More information about the plugin is available here
My project generates a Jar as the output package and uses an external War file, available on our Artifactory, as the Web Application to be deployed on Tomcat (currently using version 7). This War file contains all libs and modules required for the application to run.
I have already packaged and ran those projects outside eclipse on a "vanilla" Tomcat installation. In this scenario, the Jar my project generates is loaded on the context.xml file this way:
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/igor/workspace/myapp/myapp-2.4.3.jar"/>
Is there a way I can deploy this project on Tomcat using Eclipse and still be able to debug it? Can I use the Jar generated for this purpose or do I have to deploy the workspace project?
As for the War file, do (or can) I have to add it as an dependency?
Thanks in advance!
EDIT
We actually provide an Web Framework, which is packaged as a war. Other applications that use that framework are exported as jars and loaded into the framework through the context file as cited above.
Your question is confusing probably because of your custom plugin/classloader and deployment which is sort of orthogonal to debugging.
What I recommend is you keep whatever system you have to build/package/deploy and use JVM remote debugging. That is do not use the Eclipse WTP since you seem to have custom steps for deployment but rather build your code deploy & run a separate Tomcat instance and then run the remote debugger in Eclipse.
You will get some hotcode swapping with this method but not as much as something like JRebel.. (which you could use also) it will certainly be better than constantly redeploying.
I have a maven war project. How can I do do the following from within IntelliJ IDEA:
create .war file
deploy it to a local Tomcat
start Tomcat in debug mode
You need to configure maven-war-plugin to build your war. tomcat<x>-maven-plugin will allow you to deploy it to a tomcat instance and may in fact do the war generation too - I use JBoss at my current office so haven't got any experience with the maven tomcat integration.
see http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/ and http://maven.apache.org/plugins/maven-war-plugin/ for some more details on both of these plugins.
You can use the cargo plugin too. It works pretty well for me.
I have made my own frameworks, and I use these frameworks in my web applications. Now I have to create JAR file for my project and then copy this jar to web application lib path. Is it possible to make Maven do this for me.
(Currently I don't use Maven, because I didn't get it to work with GAE.)
Yes of course, this is possible, any build tool can do that (even a shell script).
So in maven, you define a module for your framework. You define another module for your webapp, configured as a web app, add a dependency between them. This dependancy is enough for maven to understand that your framework module jar must be included in the web application.
Here a quick introduction to maven : http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
And here a basic config file for web apps : http://maven.apache.org/guides/mini/guide-webapp.html
You can create a maven project for your framework and another one for your web application. Then you just add your framework project as a dependency to your web application and it is automatically copied to lib path.
Generate a project for your framework:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
Generate a project for your web application:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
edit pom.xml of web application and add your framework as a dependency