Can Eclipse build specific packages in a project? - java

I'm curious if there's a way to build specific packages in eclipse. For instance, if I have a project with a src folder containing
com.example.a
com.example.b
com.example.c
Is there a way to build/compile just com.example.a and com.example.c? I know there's a way to do it in ant, but hopefully there's an eclipse solution too.

Yes.
File
Export...
Java
Jar File
There you can select exactly what to build in Eclipse.
For exampe check only com.example.a and com.example.c.

You can exclude com.example.b from the build path.
For different builds/packages/assemblies (jar files?) you should use ant. That's one reason why it is integrated in eclipse.

Related

Algotrader open source project not recognized as java project in eclipse

I have downloaded the open source edition of AlgoTrader from google code and imported it in Eclipse. There are two project algotrader and algotrader-strat. But the problem is that they are not recognized by eclipse as a java projects. I realized that when I tried to add a jar file and build the path. There is not ā€œJā€ on the project folder. So my question is there a way eclipse to recognize these projects as java. And if yes how can it be done?
Thanks.
https://code.google.com/p/algo-trader/wiki/AlgoTraderDocumentation#Installation
As it uses maven, maybe you can just regenerate the Elipse project files. Something like:
mvn eclipse:eclipse
I just did a quick look at the mentioned projects (I do not know them).
From what I can see, the directories you imported are the parent projects (from a Maven point of view), whose modules are in some sub-directories. For example the algotrader project contains a sub-directory called code. This one is an Eclipse project that can be imported.

Adding plain Java project as a classpath to an eclipse plugin

I have a plain Java project (not a plugin project) which I want to add to a classpath of a eclipse plugin which I am developing. But in web projects I can add that project as a build path and it works fine. But I tried same thing in eclipse plugin, I am able to compile successfully, but at run time I am getting java.lang.ClassNotFoundException.
I know OSGi quite well and I know how to add OSGi into an classpath (using export-packages) but what I want is to add Standard, non-osgi project into an classpath, so that I wont' get runtime errors. Is there anyway I can achieve this?
I can export project as a jar file or make it as a plugin project and it would work fine. But that's not my option currently because, still that API is in pre-alpha stage, and there would be lot of changes going on. So I am trying to avoid pain of exporting it as jar file everytime. Is there any option for me other than this?
I have a similar situation: I want non-OSGi Maven dependencies integrated into the classpath of my plugin. I succeeded with a roundabout solution, which I think is the best I could get.
I have a build step outside of Eclipse where I copy the class files of the dependency into the plugin's lib folder. The lib folder is specified in MANIFEST.MF as an entry in Bundle-ClassPath and (here comes the hack) as a source folder in build.properties. That was the only way to make the plugin work both when launched from within Eclipse and when exported.

package all external classes in my jar, with Eclipse

I am working on a Hadoop project in Eclipse that depends on another one of my projects; I've included the other project in my build path, but when I export the dependent project, it only contains the classes from that same project.
Ordinarily, this would not be a problem, as I could just link the other project with the -cp flag, but Hadoop requires you to pass the jar as an argument, meaning that all of my dependencies must be inside that jar.
Is there a way, in Eclipse, to automatically build and include classes from projects that you depend on?
Thanks.
You coud use Ant to automatically build, test and export. It needs some time learning it, but its worth.
There are possible tasks (fileset, zipgroupfileset, copy) to include files, jars (unzipped) or anything into the final jar. By this way you definitly know whats inside your distribution jar and you don't need an eclipe installation running.
I suggest you take a look at maven as a build tool. You define the dependencies and build steps for each of your projects in files called pom files. The maven plugins for Eclipse (the m2e plugins) can take the configuration in the pom file and setup your Eclipse build paths and project description so that you can access the classes in your other project in Eclipse. Maven can also create a jar for you that has the classes from both projects (a "jar-with-dependencies").
In maven terms, your two projects are called "artifacts" with one having a dependency on the other.
The one downside to maven (and the cause for many negative comments about maven) is an initially steep learning curve that can be frustrating. What you're trying to do, however, is very straightforward and I expect you can find a number of examples showing you exactly what you want to do.
The first step, and that's what my answer is about, is to take a look at maven. It may seem overly complex, but it can scale to handle just about any build configuration you need as your hadoop apps get more and more complex.
You can export a project as a Runnable jar, which can be useful if you want a single jar, with dependencies included.
Select the Project. File > Export. Select the Java section. Select Runnable JAR file.
See related answer:
Eclipse: How to build an executable jar with external jar?

excluding javaclasses in java, Eclipse

I've a dynamic web project which consists multiple webservices inside. I want to export this project as a war file but I don't want to export all the webservices but only the ones I want. How can I do that? I excluded the java classes from the build path but that didn't work. Thanks in advance
Use ant to do your builds.
Set up your targets and exclusions as required.
http://www.developer.com/java/j2me/article.php/989631/Building-with-Ant-Introduction.htm
Think you can use Maven too, but I'm not familiar with it
Does right-click on the java class(es) -> Build path -> Exclude help?
I know it will remove it from build, but haven't tried it on the WAR file export.
otherwise, as Steve suggested, using ANT is your best bet.

Is there a way to export a Makefile from a Java Eclipse project?

So I have this Java project made up of several classes, some external JAR files and an executable Java program. I would like to export the whole code and external JARS to an external directory and to produce a Makefile to build the program with all the dependencies. Is there an automated way to do it?
Thank you
Tunnuz
I think I understand the question. Of course if you use an external build system like maven or ant, then we are decoupling the build process from the IDE. (But in some cases the IDE does integrate pretty closely with the build tool.)
But if you want to continue building using eclipse and to generate an ant file one fine day, then there is a tool for that. Its called EBuild. It leverages all the classpath information that eclipse already has and builds an generic ant file out of it.
Do you use maven?
If so this can be easily achieved with maven assembly.
If not, you can use ant to bundle exactly what you need.
When you right-click your project in Eclipse, there is an option called "Export". It can create build.xml for ant for your project.

Categories

Resources