Sorce code namespacing/dependancy specification. Does it exist in java?

I'm just curious if you can specify the sourcepaths in the code like you can in c++. In java, it seems like everything is dependent on environment variables or compiler setttings and all kinds of other fun volitile stuff. Is there a way of specifying all your dependancies in the source code, so you don't have to worry about cross-compiler issues (other than version problems, of course)?

[398 byte] By [zensunnia] at [2007-11-26 19:04:36]
# 1
That's where build scripts come in: http://ant.apache.org/
DrLaszloJamfa at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 2
What? I don't understand what you mean. Imports specifies the dependencies.Kaj
kajbja at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 3

Heh, but when you're specifying import statements, you're actually relying on the compiler to figure out where those imports are coming from if they're not built-in java API. So, if you mess up the paths at all, or change compiler, then you're basically pulling your hair out trying to get it straight, since documentation seems nonexistant and every compiler is different.

But yea, ant is such a load off. I heard of it before, but I didn't know why it was so good. Now I can just import the ant built and edit the xml, which is the holy grail of standardization. BTW, does javac import ant xml file? If so, can you name the command so that I can look it up?

Thanks again.

zensunnia at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 4

> Heh, but when you're specifying import statements,

> you're actually relying on the compiler to figure out

> where those imports are coming from if they're not

> built-in java API.

Yes, you specify the classpath.

> So, if you mess up the paths at

> all, or change compiler, then you're basically

> pulling your hair out trying to get it straight,

> since documentation seems nonexistant and every

> compiler is different.

I don't get this. How often do you switch compiler? I only know of a few Java compilers and they take the same arguments.

>

> But yea, ant is such a load off. I heard of it

> before, but I didn't know why it was so good.

It's a bit like make.

> Now I

> can just import the ant built and edit the xml, which

> is the holy grail of standardization. BTW, does javac

> import ant xml file? If so, can you name the command

> so that I can look it up?

No, ant invokes javac.

kajbja at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 5

> Heh, but when you're specifying import statements,

> you're actually relying on the compiler to figure out

> where those imports are coming from if they're not

> built-in java API. So, if you mess up the paths at

> all, or change compiler, then you're basically

> pulling your hair out trying to get it straight,

> since documentation seems nonexistant and every

> compiler is different.

That's not about documentation or compiler differences. That's abou you knowing where you keep your library files and telling that to your compiler.

jverda at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 6
> I only know of a few Java compilers...Like?The only up to date ones I know these days are Sun and Eclipse. Myself I don't think I would rely on the second though.So what else is there?
jschella at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 7

Ops, looks like i struck a nerve. Sorry to be so blunt, but whenever I check google for tutorials on compiler commands and configuration, all that comes up is installation helpers and definitions on what a classpath is. There's also environment variable tutorials, which don't help me either. There was even a tutorial on making a bash script for environment details.

"Yes, you specify the classpath."

Is that the javac -classpath option? Can you point me to a place that describes how it works and all ths ins and outs? I've used this command in so many variations with no avail. Nothing seems to give a straight answer on how to build a classpath if you just have the program source files.

"No, ant invokes javac."

Can you elaborate? Even if only just a link?

Thanks!

zensunnia at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...
# 8

> Ops, looks like i struck a nerve. Sorry to be so

> blunt, but whenever I check google for tutorials on

> compiler commands and configuration, all that comes

> up is installation helpers and definitions on what a

> classpath is. There's also environment variable

> tutorials, which don't help me either. There was even

> a tutorial on making a bash script for environment

> details.

It's just a different model.

> "Yes, you specify the classpath."

>

> Is that the javac -classpath option?

Yes, that's the generally preferred way. You can also use a CLASSPATH env var.

> Can you point me

> to a place that describes how it works and all ths

> ins and outs?

[url=http://wiki.java.net/bin/view/Javapedia/ClassPath]Javapedia: Classpath[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html]How Classes are Found[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]Setting the class path (Windows)[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html]Setting the class path (Solaris/Linux)[/url]

[url=http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html]Understanding the Java ClassLoader[/url]

java -cp .;<any other directories or jars> YourClassName

You get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

javac -classpath .;<any additional jar files or directories> YourClassName.java

You get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

> variations with no avail. Nothing seems to give a

> straight answer on how to build a classpath if you

> just have the program source files.

"if you just have the source files"?

So if your A.java depends on class B, and you only have B.java, you want to compile B.java and tell it where to find the resulting B.class, right?

If that's the case,then, yeah, go with ant or maven. You can do it with javac, but it gets hairy if you have multiple source trees.

On the other hand, if you're just compiling everything under one root, you can do something like this. Not sure of the details as it's been a wihle since I've done a direct javac on anything other than pwd.

(Assumes a n*x system.)

javac -d some_output_dir- classpath some_output_dir $(find com -name \*.java)

Although whatever -d points to might implicitly be on the classpath anyway.

It's hard to provide specific help as it's not clear what your specific problem is. You seem to be speaking in terms that apply to the C model but dont apply or don't have a direct analog inthe Java model.

> "No, ant invokes javac."

>

> Can you elaborate? Even if only just a link?

http://ant.apache.org/

The ant executable reads an xml file that tells it, among other things, which classes to compile, where to put the output, what jars or directories to include on the classpath during compile, and which executable to run as the compiler (usually javac).

jverda at 2007-7-9 20:53:35 > top of Java-index,Java Essentials,New To Java...