Like the question GeoLite2 database gets corrupt when added to jar, I got the error from the WAR file with the following steps:
mvn package to copy GeoLite2-City.mmdb from src/main/resources/GeoLite2-City.mmdb to war file under WEB-INF/classes/GeoLite2-City.mmdb
GeoLite2-City.mmdb was changed in the first step mvn package
I tried the plugin maven-resources-plugin as https://stackoverflow.com/a/34454312/1086907, but GeoLite2-City.mmdb is still changed by mvn package
How to troubleshoot the issue?
The maven-war-plugin can actually also filter that file.
Just like for the maven-resources-plugin, you can add that mmdb file extension as an additional extension not to be filtered:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>mmdb</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
Related
I have a maven project.
Inside that project, I have a .zip dependency that carries a jar and I need to extract that jar out of the zip dependency and have maven use the jar as a dependency. I can currently download and unpack the zip but, cannot figure out a way to add the unpacked jar as a dependency for the project during the build process.
Here is what I'm currently doing for unpacking:
<dependency>
<groupId>com.bar</groupId>
<artifactId>foo</artifactId>
<version>${foo.version}</version>
<type>zip</type>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>validate</phase>
<configuration>
<includeGroupIds>com.bar</includeGroupIds>
<includeArtifactIds>foo</includeArtifactIds>
<outputDirectory>${basedir}/target</outputDirectory>
<type>jar</type>
</configuration>
</execution>
</executions>
</plugin>
I read up on some other posts that you could try adding the jar to the class path using this.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
Even doing so I was still unable to reference the packages in foo.jar in my project.
Can someone help me?
For maven to use it without subtly breaking stuff elsewhere, you must install the jar into your local repository.
I would suppose that a combination of unpacking the zip file in target/ and then invoking install:install-file on the resulting jar could do what you need. I asked some years back how to integrate that in a normal build - you might find the answer relevant. Multiple install:install-file in a single pom.xml
Let's assume that, after unpacking the zip, you have foo.jar in your module's target folder: ${project.build.directory}/foo.jar
Having this in place, you can then declare a System Dependency pointing to that jar, e.g.
<dependency>
<groupId>foo</groupId>
<artifactId>foo.jar</artifactId>
<systemPath>${project.build.directory}/foo.jar</systemPath>
</dependency>
Tip: if you dont want to delete/re-download the jar each time you do a clean (some IDE will complain the the jar is not always present) just download it once in the ${project.basedir}.
To download the jar once, you can put your "unpack" execution in a profile that gets activated only when the jar is missing.
<profiles>
<profile>
<activation>
<file>
<missing>${project.basedir}/foo.jar</missing>
</file>
</activation>
...
</profile>
</profiles>
Some time ago, I've faced the same problem. I had a zip file as my dependency, and during the build process I need to extract it and separate the content inside my generated package.
I don't know what are you using to deliver your project, but at that time I've used the maven-antrun-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>2.6</version>
</plugin>
With this, I've used the tag unzip inside my target configuration. As you can see here or here. I just don't recommend you to use the task tag as they're using, you'd better prefer the target tag.
Hope it helps you.
I have a jar file created using maven-jar-plugin.
Is there a way to skip this jar file from getting installed in repository?
Thanks in advance.
Try this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
The reason this works is that the install plugin's only job is to take your artifact(s) and install them in your local repo.
In Maven, there are main artifacts and attached artifacts. I am not sure if you can suppress installation of the main artifact and only install the attached artifact, since assemblies are not required to provide a POM.
If this is what you really want to achieve, I would suggest breaking out the assembly to a separate artifact (with <packaging>pom</packaging>), have it depend on the jar-artifact you are trying to exclude and simply install that.
I'm using IntelliJ + Maven to generate war files.
The war is always generated in ProjectDirectory/target/projectname-version.war
After the build process is done, I want to copy the generated war file into a different location (something like cp output X:/remote/tomcat_webapps/projectname.war).
I already tried to configure the directory where maven builds the project (within the pom.xml). However, maven always deletes the containing folder and all its contents, so that is not an option.
How can I automatically copy the generated war file into a different location?
you can modify the maven war plugin in your pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>X:/remote/tomcat_webapps</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
I'm not quite sure, if it is the outputDirectory or should it be webappDirectory, like in the documentation
https://maven.apache.org/plugins/maven-war-plugin/usage.html
I wanna generated java classes from xsd files bt soome how whenever i run the code it shows the error
No Schema has been found... here is the code... Kindly help...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<includeSchema>**/*.xsd</includeSchema>
<!-- <generatepackage>org.onesync.esb.datasync.model</generatepackage> -->
<!-- The package in which the source files will be generated. -->
<packageName>org.onesync.esb.datasync.model</packageName>
<!-- The working directory to create the generated java source files. -->
<outputDirectory>src/main/java/org/onesync/esb/datasync/model</outputDirectory>
</configuration>
</plugin>
</plugins>
I don't think <includeSchema>**/*.xsd</includeSchema> is valid syntax for jaxb2-maven-plugin:xjc Try omitting that parameter.
If you don't specify schemaFiles it should use all XSD files in the schemaDirectory.
"schemaFiles -- List of files to use for schemas, comma delimited. If none, then all xsd files are used in the schemaDirectory. This parameter also accepts Ant-style file patterns." (see jaxb2-maven-plugin documentation)
BTW, it is usually a good idea to use maven's configuration parameters to refer to a directory. For example, change <schemaDirectory>src/main/resources/xsd</schemaDirectory> to <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>.
Finally, you might also want to refer to this similar SO post.
I am also using maven configuration and spent almost to compile the project stuff. Later on i came to know that it looking for the schema file i.e. schema.xsd.
If you are using the MAVEN configuration then by default you can put the schema file under the resources directory.
But if you want to specify your path for finding the schema file then you can use the includeSchema tag of schemaDescription in plugin configuration.
OR
You can use the effictive pom to search for specific tag also.
Command for effective pom in maven: mvn help:effective-pom
Thanks
Sometimes, my Talend Open Studio components have resources but not Java sources (they are purely metadata components). I need to disable the generation of JAR files in such a case.
I configured the maven-jar-plugin this way:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<forceCreation>false</forceCreation>
<skipIfEmpty>true</skipIfEmpty>
<useDefaultManifestFile>false</useDefaultManifestFile>
</configuration>
</plugin>
but I still get the ${project.name}.jar file with pom.properties, pom.cml, the manifest and an empty file App.class containing only "class {}"
While I can disable the includes of all maven stuff using this:
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
I still get a JAR with the manifest file inside it
Are there some configuration parameters I misconfigured?
Most efficient way to disable the creation of jars is to configure the maven-jar-plugin like this:
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
It will place the default jar creation in the none phase, it will never be run.
I found the solution by myself, even if it's only a workaround. I delete the JAR using a delete antrun task if /src/main/java directory doesn't exist:
<!-- remove the empty JAR if not needed -->
<if>
<not><available file="${basedir}/src/main/java" type="dir" /></not>
<then>
<delete file="${project.build.directory}/${project.name}-${project.version}.jar"/>
</then>
</if>
this task requires antcontrib to work properly and, ofc, it doesn't work if you plan to do releases with maven (but it's ok for metadata-only components, like Talend Open Studio plugins)
You can instruct maven-jar-plugin to not generate META-INF/maven/*/pom. files, as explained in Maven Archiver Reference.
Also, you can use its skipIfEmpty option.
Following code combines both these (just to have them copy-paste ready):
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
...
This works fine, but when you do mvn install, it fails due to missing project artifact.
Similar problem will probably be with mvn deploy and with release, but I didn't check these.
However, if you can live with antrun's delete, the property skipIfEmpty will probably work well for you, and is a bit more elegant. At least it does not introduce a new execution and its dependencies etc.