Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to compile using Eclipse

 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a new project and have couple of source files in there.

How can I compile these files, I can see onlt 'Run' in there.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Project menu contains the build actions (which are in part compile actions). What you need is Build Project.

However if you try Run the project will be build.

./pope
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems with getting source set properly.

When I try to run a class with main(by clicking run on the file) it is not able to find main.

How do we set the source path correctly if the java files are sitting in a different directory from the project location itself??? It was very intuitive in JBuilder(may be because I am used to it)
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you have a good reason to organize the project this way ;-).
The solution would be:
New -> Folder -> Advanced -> Linked to folder in the file system.
Than Properties -> Java Build Path -> Source -> Add Folder (the folder from the previous step).

./pope
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... another solution would be to create another project containing the sources directory structure and to make the current project depend on this new defined one.

./pope
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able figure out some of the compilation issues(that are due to setup of different project properties).

One last question: for log4j to work, I need to expose of folder(where appender xml files reside) to the project. How can I do that???
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use the -Dlog4j.configuration in run configuration.
Another solution would be to place the log4j.xml file in your build directory.

./pope
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kishore Dandu:
I have a new project and have couple of source files in there.

How can I compile these files, I can see onlt 'Run' in there.


By default of eclipse, it's auto-recompile source code when source code is changed.

But you want to manaual compile, you can do like this ::

- Cleck right at project/source in package explorer and select build project.

or

- Select Project --> Build
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kishore Dandu:
I am able figure out some of the compilation issues(that are due to setup of different project properties).

One last question: for log4j to work, I need to expose of folder(where appender xml files reside) to the project. How can I do that???


Set up Log4j in project.

1. create and put log4j.properties in your output class directory of your project.

Example to config log4j.properties



In source code




Reference Website
http://logging.apache.org/log4j/docs/
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may be I am not communicating correctly.

I am sure how to setup log4j(its xml files) and how to invoke it programatically.

But for a project that has log4j invokation in a java file, it needs to know the location of appender files(xml files).

Simply put, my question is "how do u add a directory to classpath in Eclipse"???
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of maneuvering your mouse towards the project menu, I'd suggest learning the shortcut for building your project, CTRL-B. You'll get addicted to it, I promise...
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kishore Dandu:
Simply put, my question is "how do u add a directory to classpath in Eclipse"???

Right-click your project and select Properties > Java Build Path > Libraries > Add Class Folder.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lasse Koskela:
[...]learning the shortcut for building your project, CTRL-B. You'll get addicted to it, I promise...


Lol Lasse. I use emacs style shortcuts (almost all defined by myself starting with 3.0M7)... and yes, on some projects I am addicted to CTRL-B CTRL-P ;-).

./pope
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lasse Koskela:

Right-click your project and select Properties > Java Build Path > Libraries > Add Class Folder.


I would say that using -D option on Run configuration will save some time put on editing log4j.xml (I currently use 5 different log4j configurations when testing - different logging options).

./pope
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic