You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by alexworden <al...@gmail.com> on 2008/10/16 21:44:29 UTC

Packaging an application that can be run

Hi,

I have a standalone application that needs to be run on a production
machine. I'm using the maven assembly plugin to create a zip file that
contains all of the dependencies. So far so good, however, I need a script
that can be invoked on the production machine (from a cron job). 

I can write this script myself, but I'll need to ensure that all the
dependency jars are included in the classpath. I'm hoping that the assembly
plugin or some other maven feature will help me achieve this last crucial
phase but I can't find any documentation or a single example. 

I have persuaded Maven to create an executable jar of my project and it
appears to have put all the dependencies in the Manifest file. When I invoke
it using "java -jar myExecJar.jar" it does appear to find the dependent jars
that are in the same "lib" directory as myExecJar.jar (I have no idea why). 

My problem is that I need to specify an additional path to my classpath that
contains some properties files for the target platform. If I use the
-classpath, I can no-longer invoke my executable jar. I've tried just
setting CLASSPATH but this has no effect. 

Can anyone help please?

Thanks,

Alex

-- 
View this message in context: http://www.nabble.com/Packaging-an-application-that-can-be-run-tp20016263p20016263.html
Sent from the Maven - Users mailing list archive at Nabble.com.


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


Re: Packaging an application that can be run

Posted by alexworden <al...@gmail.com>.
Hi supareno,

I'm trying not to have to manipulate the manifest by hand. It is generated
by the maven-jar-plugin and contains all the dependencies I need. I also
need to be able to speficy where the properties files are located for each
target platform. I posted my own solution to this.

Thanks for your reply,

Alex


supareno wrote:
> 
> alexworden ,
> 
> 
> did you add this to your manifest:
> 
> Class-Path: foo.jar bar.jar
> 
> and is your folder looks like this:
> 
> <appfolder>
>     |_ myExecJar.jar
>     |_ foo.jar
>     |_ bar.jar
> 
> ??
> 
> check out this
> 
> http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html
> 
> it may help you
>> Hi,
>>
>> I have a standalone application that needs to be run on a production
>> machine. I'm using the maven assembly plugin to create a zip file that
>> contains all of the dependencies. So far so good, however, I need a
>> script
>> that can be invoked on the production machine (from a cron job). 
>>
>> I can write this script myself, but I'll need to ensure that all the
>> dependency jars are included in the classpath. I'm hoping that the
>> assembly
>> plugin or some other maven feature will help me achieve this last crucial
>> phase but I can't find any documentation or a single example. 
>>
>> I have persuaded Maven to create an executable jar of my project and it
>> appears to have put all the dependencies in the Manifest file. When I
>> invoke
>> it using "java -jar myExecJar.jar" it does appear to find the dependent
>> jars
>> that are in the same "lib" directory as myExecJar.jar (I have no idea
>> why). 
>> My problem is that I need to specify an additional path to my classpath
>> that
>> contains some properties files for the target platform. If I use the
>> -classpath, I can no-longer invoke my executable jar. I've tried just
>> setting CLASSPATH but this has no effect. 
>>
>> Can anyone help please?
>>
>> Thanks,
>>
>> Alex
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Packaging-an-application-that-can-be-run-tp20016263p20023051.html
Sent from the Maven - Users mailing list archive at Nabble.com.


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


Re: Packaging an application that can be run

Posted by Dan Tran <da...@gmail.com>.
lookup appassembler plugin

On Thu, Oct 16, 2008 at 1:13 PM, supareno <re...@free.fr> wrote:
> alexworden ,
>
>
> did you add this to your manifest:
>
> Class-Path: foo.jar bar.jar
>
> and is your folder looks like this:
>
> <appfolder>
>   |_ myExecJar.jar
>   |_ foo.jar
>   |_ bar.jar
>
> ??
>
> check out this
>
> http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html
>
> it may help you
>>
>> Hi,
>>
>> I have a standalone application that needs to be run on a production
>> machine. I'm using the maven assembly plugin to create a zip file that
>> contains all of the dependencies. So far so good, however, I need a script
>> that can be invoked on the production machine (from a cron job).
>> I can write this script myself, but I'll need to ensure that all the
>> dependency jars are included in the classpath. I'm hoping that the
>> assembly
>> plugin or some other maven feature will help me achieve this last crucial
>> phase but I can't find any documentation or a single example.
>> I have persuaded Maven to create an executable jar of my project and it
>> appears to have put all the dependencies in the Manifest file. When I
>> invoke
>> it using "java -jar myExecJar.jar" it does appear to find the dependent
>> jars
>> that are in the same "lib" directory as myExecJar.jar (I have no idea
>> why). My problem is that I need to specify an additional path to my
>> classpath that
>> contains some properties files for the target platform. If I use the
>> -classpath, I can no-longer invoke my executable jar. I've tried just
>> setting CLASSPATH but this has no effect.
>> Can anyone help please?
>>
>> Thanks,
>>
>> Alex
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: Packaging an application that can be run

Posted by supareno <re...@free.fr>.
alexworden ,


did you add this to your manifest:

Class-Path: foo.jar bar.jar

and is your folder looks like this:

<appfolder>
    |_ myExecJar.jar
    |_ foo.jar
    |_ bar.jar

??

check out this

http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html

it may help you
> Hi,
>
> I have a standalone application that needs to be run on a production
> machine. I'm using the maven assembly plugin to create a zip file that
> contains all of the dependencies. So far so good, however, I need a script
> that can be invoked on the production machine (from a cron job). 
>
> I can write this script myself, but I'll need to ensure that all the
> dependency jars are included in the classpath. I'm hoping that the assembly
> plugin or some other maven feature will help me achieve this last crucial
> phase but I can't find any documentation or a single example. 
>
> I have persuaded Maven to create an executable jar of my project and it
> appears to have put all the dependencies in the Manifest file. When I invoke
> it using "java -jar myExecJar.jar" it does appear to find the dependent jars
> that are in the same "lib" directory as myExecJar.jar (I have no idea why). 
> My problem is that I need to specify an additional path to my classpath that
> contains some properties files for the target platform. If I use the
> -classpath, I can no-longer invoke my executable jar. I've tried just
> setting CLASSPATH but this has no effect. 
>
> Can anyone help please?
>
> Thanks,
>
> Alex
>
>   


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


Re: Packaging an application that can be run

Posted by alexworden <al...@gmail.com>.
Thanks Tommy - I was searching all over for that java property. I thought you
had to specify each and every jar file on the classpath.  

For the record, I found a workaround. I was having Spring pick up my
properties files from the classpath via :

	<bean id="myPropsConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:fileOne.properties</value>
				<value>classpath:fileTwo.properties</value>
			</list>
		</property>
	</bean>

That's why I wanted to manipulate the classpath. I found another approach
that allows me to pull the properties files from the filesystem, and
configure where to pull them from in an environment variable. Like so:

	<bean id="myPropsConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>file:${config.path}/fileOne.properties</value>
				<value>file:${config.path}/fileTwo.properties</value>
			</list>
		</property>
	</bean>

now, when I execute my jar I just have to specify "-Dconfig.path=./x/y/z" on
the java command line and it will be substituted in the Spring
applicationConext.xml

Thanks for your help on this!

Alex


tadamski wrote:
> 
> Alex,
> 
> I too went through this problem and hopefully I can be of some assistance
> to you.  It seems you are close to a solution, but I would like to offer a
> different approach from the executable jar.  
> 
> Within your assembly descriptor, you can output your dependent jars into a
> desired folder
> 
> <dependencySets>
>     	<dependencySet>
>     	<scope>compile</scope>
>     	<outputDirectory>lib</outputDirectory>
>     	</dependencySet>
> </dependencySets>
> 
> this puts the needed jars into a lib directory in the root of your zip
> structure, provided your project modules dependencies are configured
> properly.
> 
> In order to get java to use your jars, you must tell it to look for the
> specific lib directory: -Djava.ext.dirs="/path/to/lib"
> 
> In order to get java to pick up properties files, they need to be located
> in the java/lib/ext directory, then append that location to the above
> perhaps like this.
> -Djava.ext.dirs="/path/to/lib";"$MY_JAVA_HOME/lib/ext"
> 
> Instead of creating an executable jar, you can call your main class with
> the java command from within the script.
>    java -Djava.ext.dirs="/path/to/lib";"$MY_JAVA_HOME/lib/ext"
> foo.bar.MyMainClass
> 
> Hopefully this will help!
> 
> ~Tommy
> 
> 
> alexworden wrote:
>> 
>> My problem is that I need to specify an additional path to my classpath
>> that contains some properties files for the target platform. If I use the
>> -classpath, I can no-longer invoke my executable jar. I've tried just
>> setting CLASSPATH but this has no effect. 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Packaging-an-application-that-can-be-run-tp20016263p20017365.html
Sent from the Maven - Users mailing list archive at Nabble.com.


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


Re: Packaging an application that can be run

Posted by tadamski <th...@gmail.com>.
Alex,

I too went through this problem and hopefully I can be of some assistance to
you.  It seems you are close to a solution, but I would like to offer a
different approach from the executable jar.  

Within your assembly descriptor, you can output your dependent jars into a
desired folder

<dependencySets>
    	<dependencySet>
    	<scope>compile</scope>
    	<outputDirectory>lib</outputDirectory>
    	</dependencySet>
</dependencySets>

this puts the needed jars into a lib directory in the root of your zip
structure, provided your project modules dependencies are configured
properly.

In order to get java to use your jars, you must tell it to look for the
specific lib directory: -Djava.ext.dirs="/path/to/lib"

In order to get java to pick up properties files, they need to be located in
the java/lib/ext directory, then append that location to the above perhaps
like this.
-Djava.ext.dirs="/path/to/lib";"$MY_JAVA_HOME/lib/ext"

Instead of creating an executable jar, you can call your main class with the
java command from within the script.
   java -Djava.ext.dirs="/path/to/lib";"$MY_JAVA_HOME/lib/ext"
foo.bar.MyMainClass

Hopefully this will help!

~Tommy


alexworden wrote:
> 
> My problem is that I need to specify an additional path to my classpath
> that contains some properties files for the target platform. If I use the
> -classpath, I can no-longer invoke my executable jar. I've tried just
> setting CLASSPATH but this has no effect. 
> 

-- 
View this message in context: http://www.nabble.com/Packaging-an-application-that-can-be-run-tp20016263p20016815.html
Sent from the Maven - Users mailing list archive at Nabble.com.


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