The packaging of pom.xml is war but I need the compiled webapp folder (with html/css/js/jsp, resources, classes and lib) only, because I will do some modification and package this folder programmatically and packaging this folder into war by maven waste time.
Can I skip generating war file by mvn clean package?
if you want skip generating war file you can use war:exploded plugin
after that, you can run mvn clean compile war:exploded
Related
So I need to connect a library to my repo in IntelliJ, so I can test the library as it interacts with my main project. And I got this command from a member on my team: "So you need to change .java files in entity manager (which is the library) repo and do mvn clean package to generate the jar file locally, the use that jar in your project repo.
Then create dummy folder in your project with the same package name and copy those .java files from entity manager."
What does change the java files mean? What about "use that jar"? I'm so confused.
Use "mvn install" instead of package. This puts the library into your local .m2 repo and makes it available to your project in idea
If you do mvn clean package it produces a .jar file in target/ folder. Use that dependency to your project if they both share a common parent pom.xml
If you do mvn clean install it produces the jar file in target/ folder + copies the .jar file to your local m2 folder. That way you can use that .jar file to any project locally. Just use the with matching version, artifact and groupId whereever you need to use that jar file.
For both options above, you need to define sth like below in your pom.xml
<dependency>
<groupId>com.my.library</groupId>
<artifactId>mylib-artifact</artifactId>
<version>1.VERSION</version>
</dependency>
Not recommended:
You can also put the .jar file to your project (without doing mvn clean install) See: http://blog.gtiwari333.com/2016/12/maven-use-local-jar-without-installing.html
Or manually add the .jar to your project as project dependency using your IDE's project configuration
I am developing a web application consisting of the following structure:
enter image description here
When i execute mvn clean package, there is no file in webapp packaged into the jar.
If you are using jar as the packaging structure , put all your static resources under src/main/resources/static and it will automatically get copied into the final jar when you use the command mvn clean install. The webapp folder structure is suitable for war deployment. When the packaging is war , maven will look for the webapp folder and copy it's contents to the resulting war package.
I was reading about how to create a jar file with Maven, but I saw some pom.xml files using Maven Source Plugin and others using Maven Jar Plugin.
In the Apache Maven Project page I found these descriptions:
Apache Maven JAR Plugin
This plugin provides the capability to build jars. If you like to sign jars please use the Maven Jarsigner Plugin.
Apache Maven Source Plugin
The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.
Reading these descriptions, I stayed in doubt about when use one or other plugin, and what are the differences or benefits, because I understood that both make the same thing.
The Apache Maven JAR Plugin is used to build jar files containing .class files in order to distribute applications or libraries in bytecode format.
The Apache Maven Source Plugin is used to build jar files containing source files (.java files) in order to allow IDE to show the source code when debugging. This jar file is used in combination with the jar file containing .class files.
maven jar plugin
The jar plugin creates a JAR file from your Maven project. The jar goal of the jar plugin is bound to the package phase of the Maven default lifecycle. When you type mvn clean install, Maven will execute all the phases in the default lifecycle up to and including the install phase, which also includes the package phase.
maven source plugin
The source plugin creates a JAR file with the project source code. It defines five goals: aggregate, jar, test-jar, jar-no-fork, and test-jar-no-fork. All these five goals of the source plugin will run under the package phase of the default lifecycle.
Unlike any of the plugins we discussed before, if you want to execute the source plugin with the Maven default lifecycle, it has to be defined in the project POM file, shown as follows. The super POM file does not define the source plugin; it has to be within your Maven project itself
What is the Difference
Both create JAR files; however, the jar plugin creates a JAR file from the binary artifact, while the source plugin creates a JAR file from the source code. Small-scale open source projects use this approach to distribute the corresponding source code along with the binary artifacts.
My main problem is I have to sign all the JARs of WEB-INF\lib folder.
So this is what I have done:-
Enabled archiveClasses option to package classes also into JAR
Added JAR-Signer Plugin and setting the archive directory to ${project.build.directory}\${project.build.finalName}\WEB-INF\lib
After package finishes, I can check that in target directory all JARs in lib folder are signed but my war file contains unsigned JAR only. Most probably because the jar-signer executed after maven-war-plugin has created the war file.
I tried with setting JAR-Signer to pre-package phase also, but the lib folder is not present by then.
So what I need is to execute Maven JAR-Signer just before maven creates the war file from target directory.
Thanks
I want to know how can i remove the target folder and war file which created within webapps folder when i deploy the project.
I'm using eclipse IDE for the deploy project. I want to what is the maven plugin for this goal.
But if I used terminal for deploy the project i can used. But sometimes this command also unable to clean the webapps folder.
mvn clean compile war:war
Do you get an error message when using mvn clean ?
Do you have open files which are located in the structure under target? This prevents the target folder from being deleted.