You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Midtskogen, Erik" <Er...@anntaylor.com> on 2006/05/31 21:56:46 UTC

Stand-alone app

OK, so it seems that it's not possible to manage the build of a
stand-alone, desktop application entirely in Maven without resorting to
one or more hacks or manual processes.  I find it rather odd that the
most basic of all use-cases usually fulfilled by software build systems
is not yet supported by Maven.  But I'm willing to try my hand at
writing a plugin or goal to fulfill this need and give something back to
the Maven community.

Just to recap my earlier inquiry, what I'm looking for is a goal whose
resulting artifact is an executable jar file along with all the
dependencies it needs in order to run.  The goal would automatically
make the appropriate entries into the artifact jar's manifest.mf for the
main class and the jar file dependencies.  Then, it would copy the
dependency jar files themselves from the repository to the locations
specified in the manifest.mf.

Would anybody else here have a need for such a goal, or am I the only
one using Maven to build stand-alone Java apps?  If other people would
find such a goal useful, should I try to write it as a goal of the
assembly plugin, with the idea that I could submit it to a committer and
have it become a goal called, for example, assembly:stand-alone-app?

Any feedback or tips would be great--especially from someone who has
written a Maven goal before.

Thanks,
--Erik

***********************************************************************************
The information in this email (including any attachments) is confidential and may be legally privileged.  Access to this e-mail by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it (including any attachments) is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, all attachments, and any copies thereof from your system and destroy any printout thereof.

______________________________________________________________________
The information in this email (including any attachments) is confidential and may be legally privileged. Access to this e-mail by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it (including any attachments) is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, all attachments, and any copies thereof from your system and destroy any printout thereof.

Re: Stand-alone app

Posted by Tim Kettler <ti...@udo.edu>.
Hi Erik,

it is certainly possible to build stand-alone applications with maven. Maven just doesn't 
promotes a single way of doing this since there are many ways to create a stand-alone java 
application.

For the beginning:

You can configure the jar plugin as shown below to create the Main-Class entry and add the 
dependencies of your project to the Class-Path entry of the manifest:

<build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       <configuration>
         <archive>
           <manifest>
             <mainClass>my.package.MainClass</mainClass>
             <addClasspath>true</addClasspath>
             <classpathPrefix>Your/prefix/here</classpathPrefix>
           </manifest>
         </archive>
       </configuration>
     </plugin>
   </plugins>
</build>

 From there on some people just create a combined jar with the assembly plugin  and the 
predefined 'jar-with-dependencies' configuration that includes all files of the 
dependencies. The documentation of the assembly plugin is available here: 
http://maven.apache.org/plugins/maven-assembly-plugin/

You can also copy the dependencies of your application (with the maven-dependency-plugin) 
to a path in your target directory so that they get jarred up with the other content of 
your jar during the packaging phase. Documentation is available here: 
http://mojo.codehaus.org/dependency-maven-plugin/

Another way would be to use pomstrap to run your application:
http://pomstrap.prefetch.com/en/

Hope this helps
-Tim

Midtskogen, Erik schrieb:
> OK, so it seems that it's not possible to manage the build of a
> stand-alone, desktop application entirely in Maven without resorting to
> one or more hacks or manual processes.  I find it rather odd that the
> most basic of all use-cases usually fulfilled by software build systems
> is not yet supported by Maven.  But I'm willing to try my hand at
> writing a plugin or goal to fulfill this need and give something back to
> the Maven community.
> 
> Just to recap my earlier inquiry, what I'm looking for is a goal whose
> resulting artifact is an executable jar file along with all the
> dependencies it needs in order to run.  The goal would automatically
> make the appropriate entries into the artifact jar's manifest.mf for the
> main class and the jar file dependencies.  Then, it would copy the
> dependency jar files themselves from the repository to the locations
> specified in the manifest.mf.
> 
> Would anybody else here have a need for such a goal, or am I the only
> one using Maven to build stand-alone Java apps?  If other people would
> find such a goal useful, should I try to write it as a goal of the
> assembly plugin, with the idea that I could submit it to a committer and
> have it become a goal called, for example, assembly:stand-alone-app?
> 
> Any feedback or tips would be great--especially from someone who has
> written a Maven goal before.
> 
> Thanks,
> --Erik
> 
> ***********************************************************************************
> The information in this email (including any attachments) is confidential and may be legally privileged.  Access to this e-mail by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it (including any attachments) is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, all attachments, and any copies thereof from your system and destroy any printout thereof.
> 
> ______________________________________________________________________
> The information in this email (including any attachments) is confidential and may be legally privileged. Access to this e-mail by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it (including any attachments) is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, all attachments, and any copies thereof from your system and destroy any printout thereof.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Stand-alone app

Posted by jean-laurent de morlhon <je...@gmail.com>.
Erik,

If I understand what you want to do clearly, you can do everything
without writing a plugin.
Just use the maven-jar-plugin and maven-assembly-plugin. The following
is extracted from a standalone application I built with m2 a few month
ago (assembly plugin as slightly changed since then and spurts some
deprecation but it works fine)

First make a executable jar and putting all dependencies into the
manifest is done this way :
      <plugin>
	    <artifactId>maven-jar-plugin</artifactId>
	    <configuration>
	      <archive>
	        <manifest>
	          <mainClass>com.foo.bar.ClassHoldingAMainMethod</mainClass>
	          <addClasspath>true</addClasspath>
	          <addExtensions>true</addExtensions>
	          <classpathPrefix>./lib/</classpathPrefix>
	        </manifest>
	       </archive>
	    </configuration>
	  </plugin>

Note that classpathPrefix is ./lib, of course you can use whatever you want.


call the assembly plugin (plugin is not bound to any phase you can do
it if you want)
	  <plugin>
	     <artifactId>maven-assembly-plugin</artifactId>
	     <configuration>
	       <descriptor>assembly.xml</descriptor>
	     </configuration>
	  </plugin>

put in the assembly.xml the following :
<assembly>
  <id>distribution</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <includes>
        <include>readme.txt</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>target</directory>
      <outputDirectory></outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/lib</outputDirectory>
      <unpack>false</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

then call mvn assembly:directory.

you'll find in the target directory the resulting jar and in the lib
directory all the dependencies.

No plugin code, all is proper declaration.

hope it helps.


On 5/31/06, Lee Meador <le...@leemeador.com> wrote:
> What I do is build the executable jar. It takes two options to the jar
> plugin to put the dependent jar references in the manifest and to put ./lib
> on the front of each reference.
>
> Then I have an assembly that puts that jar and its dependency jars all
> together in a zip or tar.gz that will extract into place to run. There are
> some properties files too. The assembly xml file is 40 lines. Most of them
> just define what goes inside. The rest has mostly to do with filtering the
> resouces for different deployment environments.
>
> The pom has a few lines to tell it to do the assembly as part of a full
> build.
>
> If I didn't do the properties files the way I do it would all run just fine
> with 'java -jar ...". As is, I run from the command line without change
> after extracting from the zip or tar.gz.
>
> I'm probably missing something but there isn't that much to configure and
> any plugin would need the information about what to put in the jar, what to
> filter and so forth.
>
> On 5/31/06, Midtskogen, Erik <Er...@anntaylor.com> wrote:
> >
> > OK, so it seems that it's not possible to manage the build of a
> > stand-alone, desktop application entirely in Maven without resorting to
> > one or more hacks or manual processes.  I find it rather odd that the
> > most basic of all use-cases usually fulfilled by software build systems
> > is not yet supported by Maven.  But I'm willing to try my hand at
> > writing a plugin or goal to fulfill this need and give something back to
> > the Maven community.
> >
> > Just to recap my earlier inquiry, what I'm looking for is a goal whose
> > resulting artifact is an executable jar file along with all the
> > dependencies it needs in order to run.  The goal would automatically
> > make the appropriate entries into the artifact jar's manifest.mf for the
> > main class and the jar file dependencies.  Then, it would copy the
> > dependency jar files themselves from the repository to the locations
> > specified in the manifest.mf.
> >
> > Would anybody else here have a need for such a goal, or am I the only
> > one using Maven to build stand-alone Java apps?  If other people would
> > find such a goal useful, should I try to write it as a goal of the
> > assembly plugin, with the idea that I could submit it to a committer and
> > have it become a goal called, for example, assembly:stand-alone-app?
> >
> > Any feedback or tips would be great--especially from someone who has
> > written a Maven goal before.
> >
> > Thanks,
> > --Erik
> >
> >
> > ***********************************************************************************
> > The information in this email (including any attachments) is confidential
> > and may be legally privileged.  Access to this e-mail by anyone other than
> > the intended addressee is unauthorized.  If you are not the intended
> > recipient of this message, any review, disclosure, copying, distribution,
> > retention, or any action taken or omitted to be taken in reliance on it
> > (including any attachments) is prohibited and may be unlawful.  If you are
> > not the intended recipient, please reply to or forward a copy of this
> > message to the sender and delete the message, all attachments, and any
> > copies thereof from your system and destroy any printout thereof.
> >
> > ______________________________________________________________________
> > The information in this email (including any attachments) is confidential
> > and may be legally privileged. Access to this e-mail by anyone other than
> > the intended addressee is unauthorized. If you are not the intended
> > recipient of this message, any review, disclosure, copying, distribution,
> > retention, or any action taken or omitted to be taken in reliance on it
> > (including any attachments) is prohibited and may be unlawful. If you are
> > not the intended recipient, please reply to or forward a copy of this
> > message to the sender and delete the message, all attachments, and any
> > copies thereof from your system and destroy any printout thereof.
> >
>
>
>
> --
> -- Lee Meador
> Sent from gmail. My real email address is lee@leemeador.com
>
>


-- 
Jean-Laurent

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Stand-alone app

Posted by Lee Meador <le...@leemeador.com>.
What I do is build the executable jar. It takes two options to the jar
plugin to put the dependent jar references in the manifest and to put ./lib
on the front of each reference.

Then I have an assembly that puts that jar and its dependency jars all
together in a zip or tar.gz that will extract into place to run. There are
some properties files too. The assembly xml file is 40 lines. Most of them
just define what goes inside. The rest has mostly to do with filtering the
resouces for different deployment environments.

The pom has a few lines to tell it to do the assembly as part of a full
build.

If I didn't do the properties files the way I do it would all run just fine
with 'java -jar ...". As is, I run from the command line without change
after extracting from the zip or tar.gz.

I'm probably missing something but there isn't that much to configure and
any plugin would need the information about what to put in the jar, what to
filter and so forth.

On 5/31/06, Midtskogen, Erik <Er...@anntaylor.com> wrote:
>
> OK, so it seems that it's not possible to manage the build of a
> stand-alone, desktop application entirely in Maven without resorting to
> one or more hacks or manual processes.  I find it rather odd that the
> most basic of all use-cases usually fulfilled by software build systems
> is not yet supported by Maven.  But I'm willing to try my hand at
> writing a plugin or goal to fulfill this need and give something back to
> the Maven community.
>
> Just to recap my earlier inquiry, what I'm looking for is a goal whose
> resulting artifact is an executable jar file along with all the
> dependencies it needs in order to run.  The goal would automatically
> make the appropriate entries into the artifact jar's manifest.mf for the
> main class and the jar file dependencies.  Then, it would copy the
> dependency jar files themselves from the repository to the locations
> specified in the manifest.mf.
>
> Would anybody else here have a need for such a goal, or am I the only
> one using Maven to build stand-alone Java apps?  If other people would
> find such a goal useful, should I try to write it as a goal of the
> assembly plugin, with the idea that I could submit it to a committer and
> have it become a goal called, for example, assembly:stand-alone-app?
>
> Any feedback or tips would be great--especially from someone who has
> written a Maven goal before.
>
> Thanks,
> --Erik
>
>
> ***********************************************************************************
> The information in this email (including any attachments) is confidential
> and may be legally privileged.  Access to this e-mail by anyone other than
> the intended addressee is unauthorized.  If you are not the intended
> recipient of this message, any review, disclosure, copying, distribution,
> retention, or any action taken or omitted to be taken in reliance on it
> (including any attachments) is prohibited and may be unlawful.  If you are
> not the intended recipient, please reply to or forward a copy of this
> message to the sender and delete the message, all attachments, and any
> copies thereof from your system and destroy any printout thereof.
>
> ______________________________________________________________________
> The information in this email (including any attachments) is confidential
> and may be legally privileged. Access to this e-mail by anyone other than
> the intended addressee is unauthorized. If you are not the intended
> recipient of this message, any review, disclosure, copying, distribution,
> retention, or any action taken or omitted to be taken in reliance on it
> (including any attachments) is prohibited and may be unlawful. If you are
> not the intended recipient, please reply to or forward a copy of this
> message to the sender and delete the message, all attachments, and any
> copies thereof from your system and destroy any printout thereof.
>



-- 
-- Lee Meador
Sent from gmail. My real email address is lee@leemeador.com