I tried to packaged my project. But when I run the jar file, I find a bug.
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, D:\f
...
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine#5483163c' failed to initialize. Please see attached cause exception.
...
Caused by: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'BlockTreeOrds' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names: [Lucene50]
...
I use maven to package the project.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>db.PostgreSQL</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
The project is work when I directly run it in Intellij.
Finally, I find the solution. Using the follow maven plugin to package the project.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Related
I am trying to generate a new quick fix 4.4 message library for a custom dictionary that will be used by my initiator engine.
I have downloaded the quick fix repository to generate my new jar file from github, I then duplicated the quickfixj-messages-fix44 project under quickfixj-messages and created a new project quickfixj-messages-fix44-new, I also changed the quickfixj-messages-fix44-new pom to reflect the changes
e.g.
<artifactId>quickfixj-messages-fix44-new</artifactId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin-version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<maxmemory>3g</maxmemory>
<detectOfflineLinks>false</detectOfflineLinks>
<includeDependencySources>false</includeDependencySources>
<sourcepath>${project.basedir}/../../quickfixj-core/target/generated-sources/quickfix/fix44-new;${project.basedir}/../../quickfixj-core/target/generated-sources/quickfix/field</sourcepath>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Export-Package>quickfix.field;version="${project.version}";uses:=quickfix,quickfix.fix44new;version="${project.version}";uses:=quickfix,quickfix.field;version="${project.version}"</Export-Package>
<Import-Package>quickfix,quickfix.field;version="${project.version}"</Import-Package>
<Require-Capability>osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=${jdkLevel}))"</Require-Capability>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin-version}</version>
<configuration>
<classesDirectory>${project.basedir}/../../quickfixj-core/target/classes/</classesDirectory>
<includes>
<include>FIX44.new.xml</include>
<include>quickfix/field/*.class</include>
<include>quickfix/fix44new/**</include>
</includes>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>${maven-source-plugin-version}</version>
<configuration>
<includes>
<include>FIX44.new.xml</include>
<include>quickfix/fix44new/**</include>
<include>quickfix/field/**</include>
</includes>
</configuration>
</plugin>
also I changed under quickfixj-core pom
<Import-Package>
<!-- add dynamically-loaded version-specific message factories (optional)-->
quickfix.fix40;resolution:=optional,
quickfix.fix41;resolution:=optional,
quickfix.fix42;resolution:=optional,
quickfix.fix43;resolution:=optional,
quickfix.fix44;resolution:=optional,
quickfix.fix44new;resolution:=optional,
quickfix.fix50;resolution:=optional,
quickfix.fix50sp1;resolution:=optional,
quickfix.fix50sp2;resolution:=optional,
quickfix.fixt11;resolution:=optional,
<!-- add the required imports -->
quickfix,quickfix.field,*
</Import-Package>
<resource>
<directory>../quickfixj-messages/quickfixj-messages-fix44-new/src/main/resources</directory>
</resource>
<testResource>
<directory>../quickfixj-messages/quickfixj-messages-fix44-new/src/main/resources</directory>
</testResource>
and finally under quickfixj-distribution pom
<dependency>
<groupId>org.quickfixj</groupId>
<artifactId>quickfixj-messages-fix44-new</artifactId>
<version>${project.version}</version>
</dependency>
I was able to generate 2 jar files under target
quickfixj-messages-fix44-new-3.0.0-SNAPSHOT-sources.jar
quickfixj-messages-fix44-new-3.0.0-SNAPSHOT.jar
the thing is every time I received a message from acceptor engine I get exception under my MessageCracker saying:
java.lang.ClassCastException: class quickfix.Message cannot be cast to class quickfix.fix44new.Message (quickfix.Message and quickfix.fix44new.Message are in unnamed module of loader 'app')
I am trying to create a executable jar with Maven where all the third-party dependency jars are in the root. Included are two pics for examples, and my pom.xml
With this pom, I am getting this result just below it where the jars are broken out into folders.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:// /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.xmlrpc</groupId>
<artifactId>gz-xmlrpc-server</artifactId>
<version>1.1.0-RELEASE</version>
<packaging>jar</packaging>
<name>gz-xmlrpc-server</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.7</java-version>
<target-java-version>1.7</target-java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.surefire/surefire-junit3 -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit3</artifactId>
<version>3.0.0-M3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlrpc/xmlrpc-server -->
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<!-- mycompany -->
<dependency>
<groupId>com.mycompany.batch</groupId>
<artifactId>gz-batch-comptroller</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${java-version}</source>
<target>${target-java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<Main-Class>com.mycompany.xmlrpc.server.Server</Main-Class>
</manifest>
<manifestEntries>
<Built-By>Michael Davidson</Built-By>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.mycompany.xmlrpc.server.Server</Main-Class>
<Class-Path>.</Class-Path>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.xmlrpc.server.Server</mainClass>
</manifest>
<manifestEntries>
<Class-Path>. gz-batch-comptroller-1.0.0-RELEASE.jar</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is what I need with the full jars included.
I see other threads on this subject, and I believe my pom is correct. But, I can't seem to get there.
Thanks.
I am not sure why you are using all the 3 maven plugins - jar, shade and assembly.
Could you try using either shade or assembly plugin. You could also refer (if not already) following link to check these plugin usages:
Difference between maven plugins ( assembly-plugins , jar-plugins , shaded-plugins)
Please remove maven-assembly-plugin and maven-jar-plugin completely from pom.xml file and then just use maven-shade-plugin as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Then run mvn clean package and check generated JAR file.
I am new to maven. I have used ant and know how to bundle third party jars with my jars so that they should be available at runtime. I am writing an application which depends on Apache tika library. I am using dependency to include Apache Tika jar. And my jar gets generated successfully. My pom.xml file is
<groupId>com.nayan.parsers</groupId>
<artifactId>nayantikaparser</artifactId>
<version>0.0.1-1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-app</artifactId>
<version>0.7</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.tika</groupId>
<artifactId>tika-app</artifactId>
<version>0.7</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
At the runtime since Tika will not be available on all systems I want to bundle classes from Tika jar into my output jar. But I am not sure how to do that. I ant I used to do it in the following way
<zip destfile="dist/${jar.name}-${build.version}.jar">
<!-- Include the temporary jar -->
<zipgroupfileset file="dist/temp.jar" />
<zipgroupfileset file="lib/tika-app-1.3.jar"/>
</zip>
How to do the same using maven.
Look into Maven assembly plugin. Specifically, jar-with-dependecies case. This will ensure all the dependencies are in the jar.
If you want finer control look into Maven shade plugin. See this case.
Its too late to update but I was able to achieve the desired results. I used shade plugin for maven
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.testng</exclude>
<exclude>log4j</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I would like to skip generating 'testapidocs' folder in my 'target/site' folder after executing 'clean skip:skip' with following configuration.
Build Configuration:
<build>
<plugins>
.................
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.2</version>
</plugin>
</plugins>
.........
</build>
Reporting Configuration:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</reporting>
When i ran 'clean site:site' it is creating the following folders under 'target' directory:
target/site/apidoc
target/site/testapidocs - would like to skip this one
The Selective Javadocs Reports told us as
To run the Javadocs reports selectively, you need to include only the Javadocs reports that you prefer. As said in the FAQ, the configuration depends on the <build/> tag or <reporting/> tag used.
Using <build/> Tag
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<!-- Default configuration for all reports -->
...
</configuration>
<executions>
<execution>
<goals>
<goal>javadoc</goal>
<goal>test-javadoc</goal>
</goals>
<phase>site</phase>
<configuration>
<!-- Specific configuration for the given reports -->
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Using <reporting/> Tag
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<!-- Default configuration for all reports -->
...
</configuration>
<reportSets>
<reportSet>
<id>default</id>
<configuration>
<!-- Specific configuration for the given reports -->
...
</configuration>
<reports>
<report>javadoc</report>
<report>test-javadoc</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate</id>
<configuration>
<!-- Specific configuration for the given reports -->
...
</configuration>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
...
</project>
I hope this may help.
I'm using maven to build a jar containing generated code from an schema file using jibx. To do this I'm using the jibx-maven-plugin with the schema-codegen goal. I want to include the generated binding.xml file as part of the resulting maven jar. Is there any way of directing the jar creation to include the generated binding.xml
Currently using:
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<schemaLocation>src/main/jibx</schemaLocation>
<includeSchemas>
<includeSchema>dataoneTypes.xsd</includeSchema>
</includeSchemas>
<options>
<package>org.dataone.ns.service.types.v1</package>
</options>
</configuration>
<executions>
<execution>
<goals>
<goal>schema-codegen</goal>
</goals>
</execution>
</executions>
</plugin>
David,
Good! While including the binding.xml file is not required, it is good practice. The new jibx-maven-plugin can use this file later when creating a new binding that is based on the original schema. There are plenty of examples in the JiBX source repository.
Since JiBX is OSGi enabled, it is also good practice to add an OSGi manifest when creating your jar file. This also simplifies including the binding.xml file. Even if you don't use OSGi, your jar will work fine. Here is what your project file should look like:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dataone.ns.service</groupId>
<artifactId>org.dataone.ns.service.types.v1</artifactId>
<version>0.0.1</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/jibx</schemaLocation>
<includeSchemas>
<includeSchema>dataoneTypes.xsd</includeSchema>
</includeSchemas>
<options>
<package>org.dataone.ns.service.types.v1</package>
</options>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<goals>
<goal>bind</goal>
</goals>
<configuration>
<schemaBindingDirectory>target/generated-sources</schemaBindingDirectory>
<includes>
<include>binding.xml</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>META-INF/binding.xml=${basedir}/target/generated-sources/binding.xml</Include-Resource>
<Export-Package>org.dataone.ns.service.types.v1.*;version=${project.version}</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-extras</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
Take a look at your jar file. Your classes, the binding.xml file, and OSGi manifest entries are there!
Don Corley
jibx-maven-plugin author
You can always use maven-antrun-plugin to copy your file(set) to target/classes.
Make sure that:
you attach the jibx plugin to a phase before package - best is generate-resources
you attach the antrun execution to the same or later, but again, before package - best is generate-resources or process-resources
the jibx plugin declaration precedes antrun declaration
Then you can use something like this:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="${project.build.directory}/PATH/TO/binding.xml" todir="${project.build.outputDirectory}/PATH/IN/JAR/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
...
You can create your binding.xml in the target directory you want it to be placed in the jar like this:
...
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
...
<targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
When binding the code, you can use the refer to this directory with the <bindingDirectory> tag
You can do it using the add-resource goal of the build-helper-maven-plugin.
Example:
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/resources</schemaLocation>
<includeSchemas>
<includeSchema>foobar.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.build.directory}/generated-sources</directory>
<includes>
<include>binding.xml</include>
</includes>
<targetPath>JiBX</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
You will find the binding.xml file in your jar at:
JiBX/binding.xml