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
Related
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
I have my main web application(has its own POM) that is dependent on module A((has its own POM).
When i make a build using mvn install on web application, it dependent modules
are also built in to jar file and ultimately included under WEB-INF/lib folder of main web app.
But that does not happen in when i make build using eclipse kepler (containing both maven projects i.e main web app and its dependent module A).
When building with eclipse, it just put the modified classes under moduleA/target/classes/ folder but does not make any updated jar file and put it
under WEB-INF/lib folder of main web app.
Is there a setting where i can configure eclipse building the project same way as maven does (which will really save lot of time and help in hot deployment) ?.
It used to work in one of my projects looks like some configuration is required for this.
looks like m2e connector(i have SonarQube) needs some configuration to make eclipse build in the same fashion as maven build
When i do the project > right click > mvn install , i am able to make jar file.
But what i want is eclipse build automatically option do
the build for project/module wherever modification is done , construct the jar and include it in parent WEB-INF/lib folder if it is dependent module ?
Assuming you're using the Java EE flavour of Eclipse, you can easily deploy Maven based web applications to a local server (like Tomcat, Wildfly...) from the server view.
m2e-wtp, included in recent Eclipse Java EE distros, takes care of configuring all Eclipse settings based on your project pom.xml configuration and dependencies.
See this screencast to see how simple it is : https://www.youtube.com/watch?v=TksoKkSP208
For the record, deployment/publishing is performed by each server adapter differently. They're responsible for publishing the proper jars under the WEB-INF/lib folder of the deployed application. Dependent jar projects are automatically zipped and deployed to WEB-INF/lib without user interaction
I'm new to web apps, the play framework, heroku and dependency management.
I've created a new Heroku Play framework based Java web app and I'm trying to install the dependencies for auth0 (https://addons.heroku.com/auth0#dev).
The auth0 documentation (https://docs.auth0.com/#!/web/java) only documents how to add a dependency with Maven.
There is no "pom.xml" file within the Heroku app files as I think is normally the case with Maven in a Java app. What really confuses me, is that in some areas on the Heroku documentation, it states that Maven is used by default for Java web apps, in other areas SBT, then within the project files there is a dependencies.yml file (under the conf directory).
I'm really confused as to how dependencies in Heroku Play Java web apps are managed (if its Maven by default then where's the pom.xml file?) and how I add the dependencies for auth0 and some other .Jar files (like JSOUP). There is very little documentation or examples on the dependencies.yml file, whether it's supposed to replace/supplement something like Maven or SBT, or how to add to it.
Does anyone know what the deal is with dependency management in Heroku?
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.
What is the difference between Java projects having pom.xml and web.xml? Can projects have both these configurations at the same time?
They're completely compatible. As a matter of fact, they perform completely unrelated tasks.
pom.xml is the configuration file for Maven projects. One of its goals is to provide assistance in the compilation and building of a project when using Maven. You can think of it as an ant build.xml file or a makefile Make file if you're not familiar to Maven (actually, it can provide a lot more functionality)
web.xml is the Java EE web application deployment descriptor, where you specify for instance servlets, servlet mappings and other aspects of a webapp.
What is Maven from the Apache Maven site.
What is web.xml file and what all things can I do with it? question on SO.
The two files have nothing to do with each other.
pom.xml - Maven configuration file. Controls the build process for
the project
web.xml - Web application configuration file. Controls the deployment
and configuration of the web application
The POM file really shouldn't be deployed with the application, its just for the build process.
web.xml is an indicator that the project is running in some kind of servlet container (possibly even a full-fledged Java EE container).
pom.xml is an indicator that the project is built using the Maven build system.
Those two things are entirely orthogonal, so any given project can have none, one or both of them.
The Pom defines any dependancy libraries, it is part of Maven. This tells maven what jar files to download and store in the lib folder of your site.
Web xml is how your web project is configured.
They can both coexist as they do different things.
POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named pom.xml. http://maven.apache.org/pom.html
yes you can have both configurations at the same time.
The pom.xml is for configure your project with Maven.
The web.xml is use in all Java EE project under Tomcat for example.
You can use both, Maven is for compile and deploy your project, Tomcat is your server.