excluding javaclasses in java, Eclipse - java

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.

Related

How to put eclipse jdt jar libraries in Java Build Path?

I'm trying to use eclipse jdt, and I tried to import related modules in java source file.
I have a bunch of errors as the jdt libraries are not in Java Build Path.
I tried to open Add Libary -> Plug-in Dependencies, but it doesn't have the jdt jar files.
I could use Add External JARs to point to all the jar files, but I don't think it's a good idea considering I have to do the same thing over and over again with new projects.
In this case, how to put eclipse jdt jar libraries in Java Build Path? The java.util.Collection is found automatically. I guess there might be some easy way to setup so that jdt jar files are found automatically.
Assuming your project is an eclipse plugin project you can add the jdt as a dependency and the jars will be automatically added to the plugin dependencies
Normally, I had to use eclipse plugin for using jdt for accessing the files in the workspace, and getting the jar files and such.
However, I found this solution to be very useful for using jdt/ask. The idea is to use string as an input to the jet, and import the related jars for using the jdt APIs.
http://www.programcreek.com/2011/01/a-complete-standalone-example-of-astparser/
I had to open Configure Build Path.
Then, I could select and import all the jar files that I downloaded from the site.
Now, I am ready to use the libraries.
In you Java Build Path screen, you notice two bottons Add Variable and Add Liberary below Add External Jars. Use those options and define a new variable or new user library; Once done, add the same in the project build path.
For newer project, you can simply reuse the variable/user library.
java.util.Collection is found as it is added as library in your build path(see first item in your screenshot). I am suggesting to do the same by introducing an User Library.

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?

External jars in eclipse plug-in

I'm creating an eclipse plug-in and I'm having trouble with external jars. In my plug-in I start an application which requires some external jars. What do I have to do to export them automatically with the rest of the plug-in?
Thanks in advance :)
Open your plugin.xml
Go to Runtime tab and add your JAR in the classpath section
By following the steps below, the external JARs will be included when you export your plug-in:
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
Open the build.properties in your plug-in project and check the JARs you want to include in the build in the Binary Build section on the left.
This is an easy way, though it does create an additional plug-in.
In Eclipse:
Choose New>Other, then Plug-in Development>Plug-in from existing JAR archives.
Choose the jars you want to include.
On the next page, configure the plug-in.
In your plug-in's manifest, add the new plug-in as a dependency.
In your plug-in's Properties, add the new project under Java Build Path on the Projects tab.
Edit: You may be able to combine the jars into your plug-in by instead combining both suggestions of Zsolt and user714965 below.
This is what has worked for me. If they are truly external, and this is a project for your company that is not going to be in the "wild" and you control the environment, and you have them out on the file system say at /opt/java/lib/somedir/some.jar you can tell the bundle where to find them by adding them to the Bundle-ClassPath entry in the MANIFEST.MF under META-INF. The syntax is:
Bundle-ClassPath: .,
external:/opt/java/lib/somedir/some.jar,
external:/opt/java/lib/someotherdir/someother.jar
Also it would be prudent to use these in your build path so that you are working with the same jars in both build and runtime environments.
I have done this where the Jars are multi-purpose (such as apache-commons) on our file systems and again we control the environment.
Reference the following:
http://www.eclipsezone.com/eclipse/forums/t51870.html
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
..but as apposed to Zsolt Török (his solution did not work for me) I double-clicked on the plugin.xml, went to the build tab, at the bottom, I clicked Add JARs..., and hey presto, it showed my project, and I then navigated to lib and included the external jar, as per step 1.
The approach from Andy Thomas mostly works, but you also need to export the packages needed by the existing plugin in the new wrapper plugin so that they can be accessed by the plugin at runtime.

Can Eclipse build specific packages in a project?

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.

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