From: Arne Vajhøj on 25 Mar 2010 20:15 On 25-03-2010 09:47, bugbear wrote: > Stefan Ram wrote: >> bugbear <bugbear(a)trim_papermule.co.uk_trim> writes: >>> Well, one *could* create a script to invoke the compiler >>> and runtime components sequentially, to give the effect >>> you request, but I see little benefit. >> >> One benefit would be the possibility to use Java package >> in command lines, such as Perl is used in, say, >> >> cat cljp | perl -pe 's/\n\nFrom/\nFrom /mg' | grep ... > > Yes - I understand the "idea" but question wether > Java can (in practice) express anything very useful > in one line. The line would be too long to be useful. Arne
From: SolutionMonkey on 26 Mar 2010 12:40 On Mar 25, 4:36 am, Thomas Pornin <por...(a)bolet.org> wrote: > According to SolutionMonkey <valuemon...(a)telus.net>: > > > I'm guessing you can't do this in java since there is a separate > > compilation step, but I thought maybe there's a compile/execute tool > > or option I'm unaware of. > > The Java compiler is itself written in Java, and can be invoked > programmatically; since Java 6, the API for that is standard > (javax.tools.JavaCompiler). Also, Java supports dynamic loading > of classes, so what you look for is conceptually doable. It can > be done entirely in RAM without using files; see for instance: > http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm > > However, Java is not very appropriate for one-liners; the package, > imports, class declaration, method prototypes... are somewhat huge > and cumbersome when using a single command-line invocation. You > may want to add some pre-processing. > > Also, note that : > > -- This requires a JVM with the Java compiler, i.e. a JDK. A mere JRE > (what most people have, to run applets and applications) does not > contain the Java compiler. > > -- The kick-start of a JVM and a compilation pass tend to be > computationally expensive. I have tried; expect some delay (e.g. one > second). For usual Java tasks this is not a problem, but for a > command-line interface I expect something much more responsive. Such > delays quickly become irksome. > > --Thomas Pornin Thanks for the info Thomas. I can see what you're saying about java not being appropriate for one-liners. That's why I'm looking for another tool that would (hopefully) make some assumptions about things like package imports, etc. It was a long shot. Thanks again.
From: SolutionMonkey on 26 Mar 2010 12:45 On Mar 25, 4:49 am, bugbear <bugbear(a)trim_papermule.co.uk_trim> wrote: > SolutionMonkey wrote: > > Hi: > > > Is it possible to compile and execute a bit of java code in one line? > > I know its possible in dynamic languages like groovy. > > > e.g. groovy -e "println 'Hello World!' " > > > I'm guessing you can't do this in java since there is a separate > > compilation step, but I thought maybe there's a compile/execute tool > > or option I'm unaware of. > > Well, one *could* create a script to invoke the compiler > and runtime components sequentially, to give the effect > you request, but I see little benefit. > > BugBear Thanks BugBear. I thought about this possibility, but I'm trying to avoid building a .java file altogether. So this solution doesn't fit my need. Sorry, I wasn't specific about this. Thanks again.
From: SolutionMonkey on 26 Mar 2010 12:50 On Mar 25, 4:52 am, Alessio Stalla <alessiosta...(a)gmail.com> wrote: > On Mar 25, 5:08 am, SolutionMonkey <valuemon...(a)telus.net> wrote: > > > Hi: > > > Is it possible to compile and execute a bit of java code in one line? > > I know its possible in dynamic languages like groovy. > > > e.g. groovy -e "println 'Hello World!' " > > > I'm guessing you can't do this in java since there is a separate > > compilation step, but I thought maybe there's a compile/execute tool > > or option I'm unaware of. > > > Thanks for your comments. > > BeanShell is a Java interpreter written in Java. I have never used it, > but it might do what you ask. Thanks Alessio. I'm aware of BeanShell (as I am with groovy). Although I've never used BeanShell, I'm pretty sure it would fit my requirement. The problem is that I'm looking for something that comes with a standard JDK distribution. Otherwise, I would use groovy since I'm quite familiar with it. Sorry, I wasn't specific about this. Thanks again.
From: SolutionMonkey on 26 Mar 2010 12:57 On Mar 25, 5:15 pm, Arne Vajhøj <a...(a)vajhoej.dk> wrote: > On 25-03-2010 09:47, bugbear wrote: > > > Stefan Ram wrote: > >> bugbear <bugbear(a)trim_papermule.co.uk_trim> writes: > >>> Well, one *could* create a script to invoke the compiler > >>> and runtime components sequentially, to give the effect > >>> you request, but I see little benefit. > > >> One benefit would be the possibility to use Java package > >> in command lines, such as Perl is used in, say, > > >> cat cljp | perl -pe 's/\n\nFrom/\nFrom /mg' | grep ... > > > Yes - I understand the "idea" but question wether > > Java can (in practice) express anything very useful > > in one line. > > The line would be too long to be useful. > > Arne Thanks Arne. Yeah, I think this is the crux of the problem. A one-liner tool is only valuable if you can write a succinct code snippet. I was hoping there was a tool in the JDK that helps with this. I know groovy and beanshell could be of assistance, but I don't think either of these is packaged with the JDK. Thanks again.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: sync on local variable Next: java plugin for linux firefox 3.6 |