java - How to make a runnable jar of my maven project? -
i want make jar file of project shows error when try make jar.
till now, build jar executed using command ,
java -cp <jar file> <main class name>
.
i have done adding plugin in pom,
<plugin> <artifactid>maven-assembly-plugin</artifactid> <configuration> <descriptorrefs> <descriptorref>jar-with-dependencies</descriptorref> </descriptorrefs> </configuration> </plugin>
and running command , mvn clean
, mvn install assembly:assembly
.
but want jar, run using command java -jar <jar file>
for read this link , implemented also. shows below error,
[error] failed execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project threadpool: unable parse configuration of mojo org.apache.maven.plugins:maven-jar-plugin:2.4:jar parameter manifest: cannot find setter, adder nor field in org.apache.maven.archiver.manifestconfiguration 'addclasspath' -> [help 1]
please me making jar file, executes using java -jar
command. in advance . looking kind response.
edit no 1
i added below plugins, dependency in pom,
<!-- example dependency --> <dependencies> <dependency> <groupid>commons-lang</groupid> <artifactid>commons-lang</artifactid> <version>2.1</version> </dependency> </dependencies> ... <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-jar-plugin</artifactid> <configuration> <archive> <manifest> <addclasspath>true</addclasspath> </manifest> </archive> </configuration> </plugin> </plugins> </build>
try this
<plugin> <artifactid>maven-assembly-plugin</artifactid> <configuration> <archive> <manifest> <mainclass>your.fully.qualified.mainclass</mainclass> </manifest> </archive> <descriptorrefs> <descriptorref>jar-with-dependencies</descriptorref> </descriptorrefs> </configuration> </plugin>
this add
main-class: your.fully.qualified.mainclass
header jars's meta-inf/manifest.mf
, make runnable
you can run maven build 1 line
mvn clean package assembly:single
Comments
Post a Comment