I am generating a maven archetype using the following command "mvn archetype:generate -DgroupId=com.mycompany.core -DartifactId=myproject-core -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false", which generates the war file, now I want to build it using ear file.
I have gone through the web and some posts here that two different archetypes need to created for ear and war files. But I am not getting the starting point here.
Do I need the same archetype command which I am using to generate the structure or do I need to change the parameters? Any help would be greatly appreciated.
THANK YOU
I would suggest to use the correct archetypeArtifactId=maven-archetype-j2ee-simple instead of webapp cause EAR means Java EE application which usually contains at least two modules like:
+-- root(pom.xml)
+-- module-war (pom.xml)
+-- module-ear (pom.xml)
Related
I have a maven project which generated a jar with its pom file inside and this jar is deployed on different environment. pretty straightfoward for the moment.
I would like to execute a goal (a liquibase:update) from this pom file using only the jar produced. Is there a way to do this automatically with maven, without extracting the files from the jar beforehand ? Something like mvn -jar myJar.jar liquibase:update
Check the answer to this question, I think it can help you:
Is there a good way to use maven to run an executable jar?
I have a maven project which currently creates a war package on build. Now I need to bundle it as an ear project. Any pointers on how to do this. I added the m2e plugin and modified the pom.xml file, but, i am not able to get the directory structure as expected. I need the dir structure as below
project-name
- project-name.ear
- pom.xml
- project-name.war
- projec-name.jar
- META-INF/application.xml
Thanks.
It is strongly recommend that you organize your project structure in proper Maven style:
project-name/
- pom.xml (POM of project-name, multi-module POM)
+ project-name-jar
- pom.xml (main app JAR)
+ project-name-web
- pom.xml (WAR project to construct WAR by project-name-jar etc)
+ project-name-ear
- pom.xml (EAR project to construct EAR by project-name-war etc)
Normally I will have another child project call project-name-parent which use as parent POM for the whole project.
In Maven, you don't and you shouldn't have META-INF/application.xml as part of your source. It is generated dynamically base on configuration of maven-ear-plugin.
Is there a possibility or a workaroud to use maven-archetype-webapp archetype to generate a maven webapp with plain directory structure like
/src
/main
/java
/resources
/webapp
/test
/java
/resources
I assume that your issue is the missing java and test folders in a new project when using maven-archetype-webapp. There are no options to make that archetype to add those. Of course you could add them manually after the project was created.
You may find another archetypes in one of these lists:
http://myjeeva.com/exclusive-maven-archetype-list.html
http://docs.codehaus.org/display/MAVENUSER/Archetypes+List
If there is nothing that matches what you need I suggest creating an own archetype: http://maven.apache.org/guides/mini/guide-creating-archetypes.html
It is quite easy and if you plan to use one several times it's probably worth the effort.
Actually I am not very sure of what you are asking, I mean are you looking for an alternative solution to maven-archetype-webapp ?
With maven archetype you can create the above mentioned directory structure without any hassle, of course java and test folders will be missing there.
mvn archetype:generate -DgroupId=com.techidiocy -DartifactId=FirstWeb
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
2) If you are using eclipse IDE , then you can issue the command mentioned below to convert your maven project into an Eclipse Web Project.
mvn eclipse:eclipse -Dwtpversion=2.0
This Step 2 is optional , if you are not planning to bind it with eclipse
Thanks
I'm trying to set up maven to build my project in the specific way. I have the following structure:
pom.xml
module1
pom.xml
module2
pom.xml
module2.1
pom.xml
module2.2
pom.xml
module2.3
pom.xml
I actually want to build separate rpms based on module1, module2.2 and module2.3 and want all these rpms be included into root one. Could, please, anybody help me with that if there is any ways to do this using maven and it's plugin only. Also I want this to be done via profiles, if it's possible. All my tryings led me to nothing.
Thanks in advance!
It looks like you need the maven-assembly-plugin. You should use it and define <moduleSets/> in your assembly descriptor.
I'm participating in an open source project (ps3mediaserver) which has been moved from google code (SVN) and ANT (for build tasks) to git (GitHub) and maven. I've got my own fork (called pms-mlx), where I'd like to maintain some plugins being part of the default packaging when releasing. I'm pretty new to maven and am not too sure how the project should be structured to respect the maven way.
I'll start by describing how the environment behaved previously and will then give the thoughts about the move to maven.
Links:
Old: SVN + ANT ps3mediaserver project on google code
Old: SVN + ANT pms-mlx project on SourceForge
New: Git + Maven ps3mediaserver project on GitHub
New: Git + Maven pms-mlx project on GitHub
Old behavior:
Project structure:
+--workspace
+--plugins
+--plugin1
build.xml
+--plugin2
build.xml
+--ps3mediaserver_mlx
+--plugins
build.xml
The main project is ps3mediaserver_mlx, all plugins live in sub-folders of the workspace/plugins folder.
ps3mediaserver_mlx/build.xml contains a target BuildWithoutLibs which will build the jar of the main project and copy it to workspace/pms_no_libs.jar which will then be referenced (at this location) by the plugins.
When executing the build target of any plugin, the plugin will be build and the resulting jar copied to ps3mediaserver_mlx/plugins/[plugin_name].jar.
And finally, when packaging the application using the the build target in ps3mediaserver_mlx/build.xml, the plugins containedin workspace/ps3mediaserver_mlx/plugins will be packaged (in a exe installer for windows, dmg for OSX or tar.gz for linux).
New behavior
The project structure has been changed to this:
+-- workspace/
+-- pom.xml (global-pom)
+-- ps3mediaserver/
| +-- pom.xml (pms-pom)
| +-- src/
| ...
+-- plugins/
| +-- pom.xml (plugins-pom)
| +-- Plugin1/
| pom.xml (plugin1-pom)
| src/
| +-- Plugin2/
| pom.xml (plugin2-pom)
| src/
+-- pms-package/
+-- pom.xml (package-pom)
+-- src/main/assembly/
+-- src/main/external-resources/
Responsabilities:
global-pom The root pom containing all dependencies used by pms. This lets use the same version without redeclaring them in any plugin (is this a good idea?). Builds everything and contains a modules section to perform the same maven commands on all projects
<modules>
<module>ps3mediaserver</module>
<module>plugins</module>
<module>pms-package</module>
</modules>
pms-pom: Inherits from global-pom andbuilds the pms jar
plugins-pom: Inherits from global-pom; contains a depency for pms (which will be required for all plugins); contains a list of all modules having to be built
pluginX-pom: Inherits from plugins-pom and contains a custom configuration for a plugin
package-pom: Is responsible to package pms according to the platform it is being built on.
Does this structure represent the way maven is ment to be used?
Everything is working up to the packaging. This means the main application jar as well as all the plugins have been built and need to be packaged. The package-pom is responsible to do that.
In the original application there is only one pom.xml and the packaging is being done by using different profiles for Windows, Linux and OS X. The one I'm currently working on is for OSX and uses osxappbundle-maven-plugin, but the source code is never being packaged in the app file. That's because the packaging project doesn't inherit from the actual project anymore.
How has the built jar to be referenced in order to be packaged correctly in the app file?
I've tried referencing the jar in additionalResources and as custom class path, but never with success.
You have defined a dependency for example in the plugins/pom.xml
<dependencies>
<dependency>
<groupId>net.pms</groupId>
<artifactId>pms-mlx</artifactId>
<version>1.52.1_mlx_v0.8-SNAPSHOT</version>
</dependency>
</dependencies>
which exactly represents your parent. In other words it's wrong to define a dependency which already been defined as your parent.
It's good practice to put the modelVersion tag directly after the project tag and before the parent tag. After the parent tag put the information the current module like artifactId.
After diving into the project i noticed that you defined in your of your plugins/WebservicePlugin:
<modelVersion>4.0.0</modelVersion>
<artifactId>WebservicePlugin</artifactId>
<version>3-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>net.pms</groupId>
<artifactId>pms-plugins</artifactId>
<version>1.52.1_mlx_v0.8-SNAPSHOT</version>
</parent>
which is against the maven way for multi-module builds. You should not define a different version in this case. It should look like this:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.pms</groupId>
<artifactId>pms-plugins</artifactId>
<version>1.52.1_mlx_v0.8-SNAPSHOT</version>
</parent>
<artifactId>WebservicePlugin</artifactId>
If you have problems based on the version of the WebservicePlugin module than you should think about separating the WebservicePlugin from the rest (may be the other plugins as well).
One other things which i have noticed that you defined in many of the plugins (if not all of them) the configuration and the usage of the maven-compiler-plugin...This should be done by using a pluginManagement part in your root pom...to simplyfy maintenance of your project.
The copying of the created plugins-jars via the maven-antrun plugin into a different location whould be done different.
Repeating the license entry in every plugin is not needed cause it's inherited by the parent.