Find a .class file compiled by Eclipse

Question (s):

How can I compile only one class? How to put it in a class file (which I created)? Doesn't Eclipse just automatically compile all classes at runtime?

History:

I follow the tutorial and he tells me:

Put the compiled class in WEB-INF / classes.

Where is the class:

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 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; } } 
+6
source share
7 answers

When you save the .java file, Eclipse will compile it into a .class file if there are no 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 declared your class to belong to the org.odata4j.tomcat package. Feel free to copy this file anywhere.

+8
source

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

but even better, create a "Dynamic Web Project" in eclipse that takes care of everything for you (just use the defaults). the end result is a .war file that you can create using the menu option: file-> export

such a .war file can be deployed in any web container such as tomcat. find the autodeploy directory in your tomcat or use the tomcat management console to deploy it.

+2
source

I find the class files in Project -> Properties -> Java Build Path in the Default output folder field. For me, the default was "project-name / target / classes".

+2
source

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

javac ExampleProducerFactory.java

This will create a file called ExampleProducerFactory.class , which can be moved to the desired directory.

0
source

To work properly in Eclipse, you need to work in a "Dynamic Web Project" and not in a simple "Java Project", which is not available in the standard Java Eclipse simple download.

You either need to download, or use the Eclipse Java EE flavor, or add WTP to your current installation to get it.

Please note that an absolutely easy way to get up and work with a simple web application is to use Netbeans, which by default is correctly connected (including Tomcat) in Java EE flavor.

0
source

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

0
source

I just open the location of the java file (in the right pane of the browser Explorer โ†’ Show In โ†’ System Explorer) go to the top of the workspace and find the file name without extension. he also gives me a .class file. I just delete it.

0
source

Source: https://habr.com/ru/post/947869/


All Articles