Munaf Arshad Qazi Munaf Arshad Qazi - 1 year ago 79
Java Question

compiling and executing java from bash script

I'm trying to compile my java code using a bash script. I need to pass in arguments too, which I'm getting from another file in the same directory. My script looks like:

#!/usr/bin/env bash

MYID="$(cat $(pwd)/"
eval javac src/main/java/foo/ "$MYID"

but it thinks of my argument as another java file for compilation and gives me the error:

Class names, 'abc123', are only accepted if annotation processing is explicitly requested

P.S. abc123 is the only id in the file I need to pass.

Please help me make this work, I have been looking for solutions the whole day. :(

edit: This was a stupid question.
I just realized I was passing in arguments at the wrong place. I figured it out. thankyou!

Answer Source

You are going about this the wrong way. The javac command compiles programs. That is it. It doesn't generate source code.

Based on your comments it sounds like you should be doing something like this:

javac foo/
java foo.Bar $(cat > foo/
javac foo/

This assumes that foo.Bar is some kind of generator program that knows how to generate java source code. In reality, I expect that what you are really trying to do is some kind of source-code template expansion. There could be simpler ways to do that that writing a bespoke Java program to do it. (For example, use the "m4" utility.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download