AllieCat
AllieCat

Reputation: 3960

Find the .class file compiled by Eclipse

Question(s):

How am I supposed to compile just one class? How do I put it INTO the class file (which I've created)? Doesn't Eclipse just automatically compile all the classes at runtime?

The back story:

I'm following a tutorial and it tells me to:

Put the compiled class into WEB-INF/classes.

Where the class is:

package org.odata4j.tomcat;
import java.util.Properties;
import org.core4j.Enumerable;
import org.core4j.Func;
import org.core4j.Funcs;
import org.odata4j.producer.ODataProducer;
import org.odata4j.producer.ODataProducerFactory;
import org.odata4j.producer.inmemory.InMemoryProducer;

public class ExampleProducerFactory implements ODataProducerFactory {

  @Override
  public ODataProducer create(Properties properties) {
    InMemoryProducer producer = new InMemoryProducer("example");

    // expose this jvm's thread information (Thread instances) as an entity-set called "Threads"
producer.register(Thread.class, Long.class, "Threads", new Func<Iterable<Thread>>() {
  public Iterable<Thread> apply() {
    ThreadGroup tg = Thread.currentThread().getThreadGroup();
    while (tg.getParent() != null)
      tg = tg.getParent();
    Thread[] threads = new Thread[1000];
    int count = tg.enumerate(threads, true);
    return Enumerable.create(threads).take(count);
  }
}, Funcs.method(Thread.class, Long.class, "getId"));

return producer;
  }
 }

Upvotes: 13

Views: 85762

Answers (7)

Code-Apprentice
Code-Apprentice

Reputation: 83517

When you save your .java file, Eclipse will compile it into a .class file if there are not compiler errors. You can usually find this file in the bin subdirectory of your project. In particular, it will be in bin/org/odata4j/tomcat because you have declared your class to belong to the org.odata4j.tomcat package. Feel free to copy this file anywhere you wish.

Note: You should only use org.odata4j in your package name if you own the odata4j.org domain. Otherwise, you should choose your own package name.

Upvotes: 14

Mateus Galasso
Mateus Galasso

Reputation: 348

I find my classes files in Project -> Properties -> Java Build Path at field Default output folder. To me the default was 'project-name/target/classes'.

Upvotes: 7

Amol Patil
Amol Patil

Reputation: 248

I simply open the java file location (in package explorer right click-->Show In -->System Explorer) go to top of the workspace and search for name of the file without extension. it gives me .class file as well. I just delete it.

Upvotes: 0

Bipin
Bipin

Reputation: 11

After compiling the .java successfully, the .class will be in the bin folder under the project workspace .

Upvotes: 1

Brian
Brian

Reputation: 3131

Assuming this class is in a file called ExampleProducerFactory.java, you can compile it at the command line by navigating to the directory containing the file and typing

javac ExampleProducerFactory.java

This will create a file named ExampleProducerFactory.class which you can move to the desired directory.

Upvotes: 0

For this to work properly in Eclipse you need to be working in a "Dynamic Web Project" and not in a plain "Java project", which is not available in the standard plain Java download of Eclipse.

You either need download and use the Java EE flavour of Eclipse, or add WTP to your current install to get it.

Note that the absolutely simplest way to get up and running with a simple Web application is to use Netbeans which has this properly wired by default (including a Tomcat) in the Java EE flavour.

Upvotes: 0

necromancer
necromancer

Reputation: 24641

your java file location should be: org/odata4j/tomcat/ExampleProducerFactory.java then you can on command line do: javac org/odata4j/tomcat/ExampleProducerFactory.java which will create the compiled class file: org/odata4j/tomcat/ExampleProducerFactory.class put that in a folder WEB-INF/classes/org/odata4j/tomcat/ExampleProducerFactory.class

but better yet, create "Dynamic Web Project" in eclipse, which will take care of everything for you (just use defaults). the end result will be a .war file which you can create by the menu option: file->export

such a .war file can be deployed in any web container such as tomcat. look for an autodeploy directory within your tomcat or use the tomcat managment console to deploy it.

Upvotes: 2

Related Questions