You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by ruby francisoud <ru...@gmail.com> on 2008/01/18 10:12:45 UTC
how to run a java main class in a jar ?
Newbie question.
I'm trying to run a Hello world class with buildr using the "Java" task
http://incubator.apache.org/buildr/rdoc/classes/Buildr/Java.html#M000067
But I don't understand how to use it :(
Could you give me a hint. thanks.
Here's my buildfile:
# Generated by Buildr 1.2.10, change to your liking
# Version number for this release
VERSION_NUMBER = "1.0.0"
# Version number for the next release
NEXT_VERSION = "1.0.1"
# Group identifier for your projects
GROUP = "buildr"
COPYRIGHT = ""
LANG = "commons-lang:commons-lang:jar:2.1"
# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://www.ibiblio.org/maven2/"
# run Hello class
task :run => [:package] do |t|
puts "----------------------"
puts "Running Hello Class..."
puts "----------------------"
puts "\n"
cp = [REQUIRES, LANG]
Java.java('example.Hello', "-jar
target/buildr-#{VERSION_NUMBER}.jar", {:classpath => cp, :verbose =>
true})
end
desc "The Buildr project"
define "buildr" do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
manifest["Main-Class"] = 'example.Hello'
compile.with LANG
resources
test.compile.with LANG
test.resources
package(:jar)
end
--
Benjamin Francisoud
http://rubyscube.blogspot.com
Re: how to run a java main class in a jar ?
Posted by ruby francisoud <ru...@gmail.com>.
If I move the "task :run" in the buildr block I get this error :(
C:\developement\java\contrib\buildr>buildr run
(in C:/developement/java/contrib/buildr)
rake aborted!
Don't know how to build task 'run'
The Buildfile:
# Generated by Buildr 1.2.10, change to your liking
# Version number for this release
VERSION_NUMBER = "1.0.0"
# Version number for the next release
NEXT_VERSION = "1.0.1"
# Group identifier for your projects
GROUP = "buildr"
COPYRIGHT = ""
LANG = "commons-lang:commons-lang:jar:2.1"
# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://www.ibiblio.org/maven2/"
desc "The Buildr project"
define "buildr" do
# run Hello class
task :run => [:package] do |t|
puts "----------------------"
puts "Running Hello Class..."
puts "----------------------"
puts "\n"
cp = [REQUIRES, LANG]
Java.java('example.Hello', "-jar", project('buildr').package(:jar),
{:classpath => cp, :verbose => true})
end
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
manifest["Main-Class"] = 'example.Hello'
compile.with LANG
resources
test.compile.with LANG
test.resources
package(:jar)
end
On Jan 18, 2008 11:03 AM, Alex Boisvert <bo...@intalio.com> wrote:
> The run task should also be placed inside the project definition (nested
> inside 'define "buildr" do ... end')
>
> alex
>
>
>
> On 1/18/08, Assaf Arkin <ar...@intalio.com> wrote:
> >
> > On 1/18/08, ruby francisoud <ru...@gmail.com> wrote:
> > >
> > > Java.java('example.Hello', "-jar
> > > target/buildr-#{VERSION_NUMBER}.jar", {:classpath => cp, :verbose =>
> > > true})
> >
> >
> > These should be two separate arguments, so:
> >
> > "-jar", "target/buildr-#{VERSION_NUMBER}.jar"
> >
> > Or, you can just refer to the package created by the project:
> >
> > "-jar", project('buildr').package(:jar)
> >
> > Assaf
> >
>
--
Benjamin Francisoud
http://rubyscube.blogspot.com
Re: how to run a java main class in a jar ?
Posted by Alex Boisvert <bo...@intalio.com>.
The run task should also be placed inside the project definition (nested
inside 'define "buildr" do ... end')
alex
On 1/18/08, Assaf Arkin <ar...@intalio.com> wrote:
>
> On 1/18/08, ruby francisoud <ru...@gmail.com> wrote:
> >
> > Java.java('example.Hello', "-jar
> > target/buildr-#{VERSION_NUMBER}.jar", {:classpath => cp, :verbose =>
> > true})
>
>
> These should be two separate arguments, so:
>
> "-jar", "target/buildr-#{VERSION_NUMBER}.jar"
>
> Or, you can just refer to the package created by the project:
>
> "-jar", project('buildr').package(:jar)
>
> Assaf
>
Re: how to run a java main class in a jar ?
Posted by ruby francisoud <ru...@gmail.com>.
Ok forget about my previous mail.
I directly used java and the class, not using the project.jar file,
except frot the classpath:
cp = [REQUIRES, LANG, project('buildr').package(:jar)]
Java.java('example.Hello', {:classpath => cp})
thanks for your patience :)
On Jan 18, 2008 2:09 PM, ruby francisoud <ru...@gmail.com> wrote:
> Thanks for the tip.
>
> I still get an error message:
>
> ----------------------
> Running Hello Class...
> ----------------------
> Running java example.Hello
> Exception in thread "main" java.lang.NoClassDefFoundError: example/Hello
> rake aborted!
> Failed to execute java example.Hello, see errors above
> C:/developement/java/contrib/buildr/buildfile:22
> (See full trace by running task with --trace)
>
>
> Any idea ?
> I unzipped the jar and I can see the .class file in the correct package...
>
>
>
> On Jan 18, 2008 10:58 AM, Assaf Arkin <ar...@intalio.com> wrote:
> > On 1/18/08, ruby francisoud <ru...@gmail.com> wrote:
> > >
> > > Java.java('example.Hello', "-jar
> > > target/buildr-#{VERSION_NUMBER}.jar", {:classpath => cp, :verbose =>
> > > true})
> >
> >
> > These should be two separate arguments, so:
> >
> > "-jar", "target/buildr-#{VERSION_NUMBER}.jar"
> >
> > Or, you can just refer to the package created by the project:
> >
> > "-jar", project('buildr').package(:jar)
> >
> > Assaf
> >
>
>
>
>
> --
> Benjamin Francisoud
> http://rubyscube.blogspot.com
>
--
Benjamin Francisoud
http://rubyscube.blogspot.com
Re: how to run a java main class in a jar ?
Posted by ruby francisoud <ru...@gmail.com>.
Thanks for the tip.
I still get an error message:
----------------------
Running Hello Class...
----------------------
Running java example.Hello
Exception in thread "main" java.lang.NoClassDefFoundError: example/Hello
rake aborted!
Failed to execute java example.Hello, see errors above
C:/developement/java/contrib/buildr/buildfile:22
(See full trace by running task with --trace)
Any idea ?
I unzipped the jar and I can see the .class file in the correct package...
On Jan 18, 2008 10:58 AM, Assaf Arkin <ar...@intalio.com> wrote:
> On 1/18/08, ruby francisoud <ru...@gmail.com> wrote:
> >
> > Java.java('example.Hello', "-jar
> > target/buildr-#{VERSION_NUMBER}.jar", {:classpath => cp, :verbose =>
> > true})
>
>
> These should be two separate arguments, so:
>
> "-jar", "target/buildr-#{VERSION_NUMBER}.jar"
>
> Or, you can just refer to the package created by the project:
>
> "-jar", project('buildr').package(:jar)
>
> Assaf
>
--
Benjamin Francisoud
http://rubyscube.blogspot.com
Re: how to run a java main class in a jar ?
Posted by Assaf Arkin <ar...@intalio.com>.
On 1/18/08, ruby francisoud <ru...@gmail.com> wrote:
>
> Java.java('example.Hello', "-jar
> target/buildr-#{VERSION_NUMBER}.jar", {:classpath => cp, :verbose =>
> true})
These should be two separate arguments, so:
"-jar", "target/buildr-#{VERSION_NUMBER}.jar"
Or, you can just refer to the package created by the project:
"-jar", project('buildr').package(:jar)
Assaf