You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jacob Beard <jb...@cs.mcgill.ca> on 2010/11/09 13:34:04 UTC

Maven integration with bash script

Hi,

My project is built around Mozilla Rhino, but and I'm transitioning to 
maven for the build system. When my project was using ant, I had a task 
that would download dependencies to the local lib/ directory in the 
project. I then had a shell script that would run the project, including 
the rhino library and other libraries on the classpath by refering to 
its local path. So something like this:

java -cp 
lib/java/js.jar:lib/java/commons-cli.jar:lib/java/serializer.jar:lib/java/xalan.jar:lib/java/xercesImpl.jar:lib/java/xml-apis.jar 
org.mozilla.javascript.tools.shell.Main -debug $*

With maven, however, the libraries are now kept in the location of the 
maven repository, several directories deep, based on information kept in 
the pom.xml file. I'd like to know, is there a maven solution for 
extracting a particular classpath from a maven file, such that the 
classpath can be used from a shell script? If not, is there at least a 
reliable way of determining the location of the maven repository on 
Windows and Unix platforms?

I'd appreciate any guidance anyone can provide. Thanks,

Jake

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


Re: Maven integration with bash script

Posted by Ron Wheeler <rw...@artifact-software.com>.
Start by getting it working with Eclipse and Maven.
Tell Maven and Eclipse that you are trying to build a standalone 
application when you create the Eclipse project.
It will structure your project so that it builds one with the assets in 
the right place to run it.

Points to remember
1) Don't fight Maven. It always wins.
2) Lots of people are building whatever it is that you are building and 
have already solved ALL the typical problems and built these solutions 
into Maven and Eclipse.
3) If it doesn't work, you have done something wrong. This is the 
hardest one to deal with
4) Get the basics right first and customize later once you know how it 
should hang together.
5) When asking a question in the forum, ask in terms of what you are 
trying to accomplish not how. You will get much better advice if people 
know what you want to accomplish as a result. "How should I set up maven 
to build a standalone Java application(compiler)?" than "How do I make 
maven tell Ant about classpaths?".

The members here are really great and very helpful.
You will get all the support that you need to make this work well.

Ron

On 09/11/2010 8:29 AM, Jacob Beard wrote:
> Hi Ron,
>
> Thanks for the reply.
>
> On 10-11-09 02:06 PM, Ron Wheeler wrote:
>> If you are using a decent IDE (Eclipse STS for example) with Maven 
>> support, you should not need any of this.
>> Maven and Eclipse will get everything you need onto the classpath.
>>
> My project is a compiler, so I feel that it's important that it be 
> accessible from the command line, just as it's not necessary to fire 
> up an Netbeans in order to use javac.
>
> I can think of a hacky solution that might work, which is to pass the 
> classpath from Maven to Ant using Maven Ant Tasks, and then allow Ant 
> to echo it out. But I was hoping that this might be a solved problem, 
> and that there might be a cleaner "maven solution" to making this work.
>
> I'd appreciate any advice you can offer. Thanks,
>
> Jake
>
> ---------------------------------------------------------------------
> 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: Maven integration with bash script

Posted by Jacob Beard <jb...@cs.mcgill.ca>.
Hi Ron,

Thanks for the reply.

On 10-11-09 02:06 PM, Ron Wheeler wrote:
> If you are using a decent IDE (Eclipse STS for example) with Maven 
> support, you should not need any of this.
> Maven and Eclipse will get everything you need onto the classpath.
>
My project is a compiler, so I feel that it's important that it be 
accessible from the command line, just as it's not necessary to fire up 
an Netbeans in order to use javac.

I can think of a hacky solution that might work, which is to pass the 
classpath from Maven to Ant using Maven Ant Tasks, and then allow Ant to 
echo it out. But I was hoping that this might be a solved problem, and 
that there might be a cleaner "maven solution" to making this work.

I'd appreciate any advice you can offer. Thanks,

Jake

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


Re: Maven integration with bash script

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 09/11/2010 7:34 AM, Jacob Beard wrote:
> Hi,
>
> My project is built around Mozilla Rhino, but and I'm transitioning to 
> maven for the build system. When my project was using ant, I had a 
> task that would download dependencies to the local lib/ directory in 
> the project. I then had a shell script that would run the project, 
> including the rhino library and other libraries on the classpath by 
> refering to its local path. So something like this:
>
> java -cp 
> lib/java/js.jar:lib/java/commons-cli.jar:lib/java/serializer.jar:lib/java/xalan.jar:lib/java/xercesImpl.jar:lib/java/xml-apis.jar 
> org.mozilla.javascript.tools.shell.Main -debug $*
>
> With maven, however, the libraries are now kept in the location of the 
> maven repository, several directories deep, based on information kept 
> in the pom.xml file. I'd like to know, is there a maven solution for 
> extracting a particular classpath from a maven file, such that the 
> classpath can be used from a shell script? If not, is there at least a 
> reliable way of determining the location of the maven repository on 
> Windows and Unix platforms?
>
> I'd appreciate any guidance anyone can provide. Thanks,
>
> Jake
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

If you are using a decent IDE (Eclipse STS for example) with Maven 
support, you should not need any of this.
Maven and Eclipse will get everything you need onto the classpath.

Ron
Ron


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


Re: Maven integration with bash script

Posted by Jacob Beard <jb...@cs.mcgill.ca>.
The exec-maven-plugin turned out to be a good solution. Now the shell 
script simply delegates to maven:

mvn -q exec:java -DscxmlInputArgs="$*"

And the .bat script is virtually the same thing. Very clean and simple, 
I think.

Thanks for your help with this,

Jake

On 10-11-09 02:25 PM, Benjamin Bentmann wrote:
> Jacob Beard wrote:
>
>> With maven, however, the libraries are now kept in the location of the
>> maven repository, several directories deep, based on information kept in
>> the pom.xml file. I'd like to know, is there a maven solution for
>> extracting a particular classpath from a maven file, such that the
>> classpath can be used from a shell script? If not, is there at least a
>> reliable way of determining the location of the maven repository on
>> Windows and Unix platforms?
>
> The structure of the local repository should be considered an 
> implementation detail and hard-coding paths to its contents should be 
> avoided.
>
> [0] and related goals from the maven-dependency-plugin can be used to 
> create a lib directory of user-specified structure.
>
> Maybe usage of the exec-maven-plugin [1] might be able to replace your 
> shell script completely.
>
>
> Benjamin
>
>
> [0] 
> http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html 
>
> [1] http://mojo.codehaus.org/exec-maven-plugin/
>
> ---------------------------------------------------------------------
> 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: Maven integration with bash script

Posted by Benson Margulies <bi...@gmail.com>.
maven-appassembler-plugin? maven-dependency-plugin, especially
combined with a MANIFEST.MF class path?

On Tue, Nov 9, 2010 at 8:31 AM, Jacob Beard <jb...@cs.mcgill.ca> wrote:
>
> On 10-11-09 02:25 PM, Benjamin Bentmann wrote:
>>
>> Jacob Beard wrote:
>>
>>> With maven, however, the libraries are now kept in the location of the
>>> maven repository, several directories deep, based on information kept in
>>> the pom.xml file. I'd like to know, is there a maven solution for
>>> extracting a particular classpath from a maven file, such that the
>>> classpath can be used from a shell script? If not, is there at least a
>>> reliable way of determining the location of the maven repository on
>>> Windows and Unix platforms?
>>
>> The structure of the local repository should be considered an
>> implementation detail and hard-coding paths to its contents should be
>> avoided.
>>
>> [0] and related goals from the maven-dependency-plugin can be used to
>> create a lib directory of user-specified structure.
>>
>> Maybe usage of the exec-maven-plugin [1] might be able to replace your
>> shell script completely.
>>
> Great links, I think these are both really promising approaches. Thanks for
> the insight.
>
> Jake
>
> ---------------------------------------------------------------------
> 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: Maven integration with bash script

Posted by Jacob Beard <jb...@cs.mcgill.ca>.
On 10-11-09 02:25 PM, Benjamin Bentmann wrote:
> Jacob Beard wrote:
>
>> With maven, however, the libraries are now kept in the location of the
>> maven repository, several directories deep, based on information kept in
>> the pom.xml file. I'd like to know, is there a maven solution for
>> extracting a particular classpath from a maven file, such that the
>> classpath can be used from a shell script? If not, is there at least a
>> reliable way of determining the location of the maven repository on
>> Windows and Unix platforms?
>
> The structure of the local repository should be considered an 
> implementation detail and hard-coding paths to its contents should be 
> avoided.
>
> [0] and related goals from the maven-dependency-plugin can be used to 
> create a lib directory of user-specified structure.
>
> Maybe usage of the exec-maven-plugin [1] might be able to replace your 
> shell script completely.
>
Great links, I think these are both really promising approaches. Thanks 
for the insight.

Jake

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


Re: Maven integration with bash script

Posted by Benjamin Bentmann <be...@udo.edu>.
Jacob Beard wrote:

> With maven, however, the libraries are now kept in the location of the
> maven repository, several directories deep, based on information kept in
> the pom.xml file. I'd like to know, is there a maven solution for
> extracting a particular classpath from a maven file, such that the
> classpath can be used from a shell script? If not, is there at least a
> reliable way of determining the location of the maven repository on
> Windows and Unix platforms?

The structure of the local repository should be considered an 
implementation detail and hard-coding paths to its contents should be 
avoided.

[0] and related goals from the maven-dependency-plugin can be used to 
create a lib directory of user-specified structure.

Maybe usage of the exec-maven-plugin [1] might be able to replace your 
shell script completely.


Benjamin


[0] 
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html
[1] http://mojo.codehaus.org/exec-maven-plugin/

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