Tutorial or info on simple user runtime library [message #271372] |
Wed, 03 June 2009 19:01  |
Eclipse User |
|
|
|
I'm trying to create a very simple runtime library (jarfile) that simply
has a function to print "hello world" and an executable that does nothing
but call this simple function in the jarfile. I have an Eclipse Workspace
with the two files in two separate projects. I need to be able to debug
and step into the source code in the jar runtime library. I'm having
enormous difficulty doing this; either the "include" line in the
executable doesn't work or Eclipse complains that it cant find the source
code when I try to step into the runtime library (depending on how I
change the configuration). My code is below. Can anyone recommend a
tutorial that demonstrates how to do this (or can anyone explain all the
configuration steps for the workspace and the project files)?
####### Executable project: myexe.java ##############
package org.exepath;
import org.myjarpak.*;
public class CallHello {
public static void main(String[] args) {
HelloJar Hj = new HelloJar();
Hj.sayHello();
}
}
######################################################
######## Jar project: HelloJar.java ######################
package org.myjarpak;
public class HelloJar {
public HelloJar() {
System.out.println("Hello from constructor");
}
public void sayHello () {
System.out.println("Hello World");
}
}
######################################################
|
|
|
|
|
|
Re: Tutorial or info on simple user runtime library [message #271404 is a reply to message #271372] |
Fri, 05 June 2009 13:37   |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
If both projects are part of your workspace, it would be much simpler to
simply introduce a dependency from Project A to Project B (the JAR
project) and avoid building a JAR.
Open the properties for Project A (the "executable" as you call it) and
select the Java Build Path section, then the Projects tab. There you can
add Project B (the JAR-producing project). If you've got a JAR of
Project B on Project A's build path, remove it; now that the projects
depend directly you don't need (or want) a JAR interfering.
Hit OK and the projects will rebuild.
Also, don't forget to edit the Launch Configuration that is used to
launch Project A and remove the Project B jar from its classpath (if
launching Project A does not require any special arguments or other
tweaking of the Lauch Config, it would be better to delete the launch
config altogether and then let Eclipse re-create a new one by
right-clicking on Project A and choosing Run As...)
With this setup, not only can you avoid the need to re-export the JAR
all the time, but any changes you make to Project B code will be
immediately seen in Project A (at both build time and runtime). And
source lookup just works.
Another piece of advice: open the Help Contents and navigate to the Java
Development User Guide, Getting Started section; there you'll find a
Project Configuration tutorial that will help you a lot.
Hope this helps,
Eric
pjc wrote:
> I'm trying to create a very simple runtime library (jarfile) that simply
> has a function to print "hello world" and an executable that does
> nothing but call this simple function in the jarfile. I have an Eclipse
> Workspace with the two files in two separate projects. I need to be
> able to debug and step into the source code in the jar runtime library.
> I'm having enormous difficulty doing this; either the "include" line in
> the executable doesn't work or Eclipse complains that it cant find the
> source code when I try to step into the runtime library (depending on
> how I change the configuration). My code is below. Can anyone recommend
> a tutorial that demonstrates how to do this (or can anyone explain all
> the configuration steps for the workspace and the project files)?
>
>
> ####### Executable project: myexe.java ##############
> package org.exepath;
>
> import org.myjarpak.*;
>
> public class CallHello {
>
> public static void main(String[] args) {
> HelloJar Hj = new HelloJar();
> Hj.sayHello();
>
> }
>
> }
> ######################################################
>
>
> ######## Jar project: HelloJar.java ######################
> package org.myjarpak;
>
> public class HelloJar {
> public HelloJar() {
> System.out.println("Hello from constructor");
> }
> public void sayHello () {
> System.out.println("Hello World");
> }
>
> }
>
> ######################################################
>
>
>
|
|
|
Re: Tutorial or info on simple user runtime library [message #271406 is a reply to message #271385] |
Fri, 05 June 2009 13:39  |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
pjc wrote:
> Okay I think I've found out what the problem is. I had my workspace in
> one directory hierarchy and my project files in a complete separate and
> distinct directory hierarchy. I did this because the GUI allowed me to
> do it and I didn't see anything in the documentation discouraging it.
> The problem arises when I "Export" the jarfile for the HelloJar
> project. The GUI asks me to specify a directory location for the output
> jar file but the interface is confusing. The interface just shows the
> project name as the toplevel for everything. Usually this "project
> name" is a label mapping to a location in the Project directory
> hierarchy but sometimes it is a label mapping to a location in the
> Workspace hierarchy. When Exporting a jarfile, the project name is a
> label in the Workspace hierarchy so the Jarfile ends up in the Workspace
> hierarchy (which in this case is different from the project hierarchy).
> At runtime, this seems to cause the workspace to get confused as to the
> location of the sources. I think this should really be considered an
> interface/usablity bug.
>
> THE SOLUTION: If two Eclipse projects are in one workspace, the project
> directories should be under the workspace directory; otherwise there
> could be problems (there's probably a workaround for this but for
> beginners this recipe is probably the safest).
I don't think that the physical location of your projects really has any
affect (many people set up their projects outside of the workspace
directory, including myself). See my other reply to this thread; I think
you've got an unnecessarily complex project set-up that can be
simplified by setting up the project dependencies correctly.
Hope this helps,
Eric
|
|
|
Powered by
FUDForum. Page generated in 0.07704 seconds