Can i save comment info in my Jar file(generated by Ant)? - eclipse

When I build my project to a Jar file with Ant, I generate javadoc the same time.
But when I use this Jar in a new Project, I can't see the Jar's comment in the Eclipse(pressing F2).
So I tried to add the javadoc files' location path in 'javadoc Location' of Properties of my new Project,it doesn't work, even if Eclipse tell me the 'Location is likely valid'.
When I open it in Browser,the Url is like file:///file:/C:/Users/topxebec/Desktop/doc/index.html, there's two prefix in the url,but in the eclipse I only have file:/C:/Users/topxebec/Desktop/doc/index.html,.
I tried to change it to C:/Users/tongxuebin/Desktop/doc/ but Eclipse said it was a Invalid URL.
So how to solve this problem? Or,can I simply save the comments in the Jar when it generated by Ant?

It seems, that you can't put the javadoc in the same jar as the class files, so that eclipse will automatically show the doc.
A solution is to include the source-code. This will also help, if you need to debug the classes in that jar.
This answer: How can I build my jar file so that users who use the library will be able to see the javadoc in Eclipse covers that case. But it just boils down to:
<target name="jar.noCompile.src">
<jar destfile="${ant.project.name}.jar">
<fileset dir="${classes}"/>
<fileset dir="${src}" includes="**/*.java"/>
</jar>
</target>

Related

Domino Designer Plugin Ant class path

I've build an osgi plug-in to wrap a jar files. I've been following this guide.
In the last step, I can´t “Build all” to generate the update site because an error said that couldn't find the ant classpath
Any idea?
Thanks
The version that i'm using is Release 9.0.1FP9
Revision 20170815.0729-FP9 (Release 9.0.1FP9)
Try running Ant on the command line to see the full output. Here is a GitHub project showing specifically how to run Ant tasks for Domino.
Here also are some details about setting the Ant classpath for a given build in build.xml:
<!-- create our ant classpath using the fileset task -->
<path id="class.path">
<!-- include all jars in the lib directory and all sub-directories -->
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
I find that Eclipse plugins often just assemble and execute terminal commands, but when they fail they tend not to be great at making clear the cause. Often, running the equivalent commands in the terminal (be they ant, maven, etc.) is clearer when failures occur because you'll see the full error output. And it gives you the added benefit--sometimes--of having a clearer understanding of what's happening under the hood.

Include documentation in a JAR file

With Eclipse it is possible to attach a documentation folder to a jar file in order to see the jar classes' documentation while programming. My question is: is it possible to directly include the documentation into the jar file, in order to avoid the programmer to link the two parts every time they need to use the jar file? (and so to let me to distribute just a jar file, rather than a zip file with the jar and its documentation).
EDIT
final result: it is impossible. :(
I didn't get what do you mean with "directly include the documentation", but you can put anything in the jar file. If you use ant (it can be inside Eclipse), just create a target for your distribution build and pass the documentation folder to Jar task.
<jar destfile="${dist}/lib/app.jar">
<fileset dir="${build}/classes"
excludes="**/Test.class"
/>
<fileset dir="${src}/documentation"/>
</jar>

How to include a resource file in the Jar file generated by Netbeans?

I'm using NB6.7 to auto generate an executable jar file for my project, how and where to tell NB to include a certain resource into the result jar file ? I know if I put the resource in the "lib" directory, NB will put it into "dist/lib/", but what I want is to include the resource within the final executable jar, where in NB do I specify that ?
Frank
There is a way to add arbitrary file/folders to arbitrary location within the jar, without setting up source folders.
NetBeans will, by default, create build.xml at project root.
We can override the -pre-jar target to copy the files and -post-jar target to cleanup.
For example, to copy "res/resource.ext" into "myres/resource.ext" within the jar, add these target to build.xml:
<target name="-pre-jar">
<!-- Single file -->
<copy file="res/resoure.ext" todir="${build.dir}/classes/myres" />
<!-- Folder(s) -->
<copy todir="${build.dir}/classes/myres"><fileset dir="res"/></copy>
</target>
<target name="-post-jar">
<delete dir="${build.dir}/classes/myres/resource.ext" />
<delete dir="${build.dir}/classes/myres"/>
</target>
Since this is Ant, you have great control.
You can rename file, replace file content (e.g. update version or timestamp), convert charset, or run other operations that is not possible with simple inclusion.
I am using NetBeans version 8, but as long as the project is compatible it is likely to work.
Alternatively, use an automated project such as Maven or Gradle, that gives you even more control on the build process, at cost of IDE features such as automatic single file recompile.
I got it : put the resource file in the src dir.
you can do it by...
Go to your project name which is normally on the left hand side of the screen.
Whatever your project name is,
you have to right click on it and then go to the properties of that. [which is normally at the end in menu item]
Then one window will open in that go to the Libraries.
In that you will find
1)ADD PROJECT
2)ADD Libraries
3)ADD JAR FILE
then include the jar / Libraries / folder.
so that will add automatically to your project.
Which will include in lib folder automatically so you don't have to include always.
Hope this help you,

Eclipse 3.4 GWT 1.6 project - how to reference source from other projects?

I've got a GWT 1.6 project in Eclipse 3.4 and am trying to reference source from another (non-GWT) project in my workspace. I've added the project to my build path, but I can't run the application in hosted mode. When I do, I get a "no source code is available" error.
I've done some searching and reading and have tried a few things that others have suggested (including creating a jar from the dependent project and linking to it), but frankly nothing has worked.
If you're actually doing this, could you please help me out with a simple step-by-step setup? I'd really appreciate it, thanks!
I have 2 Eclipse Projects. One is gwt project and one is not. Here's the directory structure that works for me:
workspace
-- gwt-project
-- src/main/java
-- com.gwt.GwtProjectModule
-- GwtProjectModule.gwt.xml
-- non-gwt-project
-- src/main/java
-- com.nongwt.package.that.contains.source.you.need
-- nongwt.gwt.xml
-- com.nongwt.package.that.contains.source.you.need.client
nongwt.gwt.xml tells gwt to look inside "client" package, here's what it looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='nongwt'>
<inherits name='com.google.gwt.user.User' />
<source path="client" />
</module>
GwtProjectModule.gwt.xml can then inherit source code from nongwt. Here's the relevant line from inside GwtProjectModule.gwt.xml:
<inherits name="com.nongwt.package.that.contains.source.you.need.nongwt" />
Make sure you include non-gwt-project inside gwt-project's classpath in eclipse. It's the normal drill; right click on gwt-project, choose properties, choose "Java Build Path", click "Projects" tab, and "non-gwt-project"
Or, instead of including non-gwt-project in gwt-project's classpath as a project reference, you can also jar the contents of non-gwt--project, ensure that you include the source in the jar, and then include the jar in gwt-project's classpath.
Good Luck!
I know this post is quite old but as I spent quite a lot of time on this issue and finally found the way to do it, I thought I might share the answer :
once you've created your launch configuration, open it run>run configurations...
go to classpath tab and select user entries. add advanced>folder and select the source folder of your other module project. If as me you've separated the module conf file in a src/main/resources folder you have to add it as well.
should work.
The client-side code in your GWT project (the classes under the client package) can't reference any classes that aren't in a GWT module.
If you've got code in another project that you want to reference from client code in your GWT project, you need to:
Make sure it's all "GWT safe", which means it doesn't reference any JRE classes that aren't emulated by GWT (http://code.google.com/webtoolkit/doc/1.6/RefJreEmulation.html), or reference any classes that reference JRE classes not emulated
Make sure all referenced classes are within a GWT module. This means putting a MyOtherProject.gwt.xml file in your other project, and all the referenced classes must be under a client subpackage
Make your GWT project inherit from the other project. So add the following to your GWT project's gwt.xml module file:
<inherits name='com.yourCompany.otherProject.MyOtherProject' />
Boden: add the following to your module file
<source path=""></source>
in addition to your other sources, eg:
<source path=""></source>
<source path="com.acme.otherpackage"></source>
then the compiler won't complain.
Atleast that's how I solved it. Not sure if using path="" allows inclusion of everything, I'm assuming it's the default value when no sources are specified.
This is a fantastic solution of your problem proposed by Sven Buschbeck (must a norwegian, lol!), worked for me!
When work­ing on sev­eral large scale projects (in Eclipse), it’s con­ve­nient and of course more effi­cient to share and reuse code via com­mon libraries. While those are in an early stage they need to be changed a lot and there­fore it’s handy to link projects in instead of cre­at­ing new jars each time the library has been updated.
Unfor­tu­nately, this stan­dard approach for Java devel­op­ment in Eclipse does not work that straight for­ward as with plain old Java projects, it requires three steps in total:
Link the library project to all rel­e­vant projects (“Project
Pref­er­ences” -> “Java Build Path” -> “Projects” -> “Add…”)
Then, add the client-side code of the library (by adding it as a
mod­ule.) There­fore, edit the gwt.xml of your appli­ca­tion and add
for exam­ple
where Super­Lib is the file name of the gwt.xml file in you library
project and before that is the pack­age it lies in.
Add the code to the project by link­ing a source folder.
Unfor­tu­nately, this is required if you do not want to write an Ant
script to com­pile your appli­ca­tion. (If you pre­fer Ant check
this out) I don’t like the idea of using such a script because if
you for­get to run it each time you make changes, you will end up in
confusion—let’s go for the con­ve­nient, auto­matic way then.
Add a folder to your appli­ca­tion project; open the “advanced” sec­tion in the folder cre­ation dia­log, select “Link to alter­nate loca­tion” and pick the source folder (usu­ally “src”) of your library project. (Hint: if you work within a team using a ver­sion­ing sys­tem, you can cre­ate a vari­able for that folder and use this instead. This way, each of your col­leagues can put the library project in a dif­fer­ent folder and accom­mo­date for that by adjust­ing the vari­able :) )
Right click the folder, “Build Path” -> “Use as Source Folder”. Done.
Sur­pris­ingly, the GWT plu­gin for Eclipse does not honor the project link­ing, thus all the ref­er­ences need to be made explicit or you will end up with lots of the fol­low­ing: ClassNotFoundException.
GWT doesn't know about that other code because it is not in the client directory of your project. You need to add the source path for the other code to the .gwt.xml file. Just added it to the xml as follows
<source path="common" />
common is the directory where the extra code is for this example.
Check out the XML Element Reference section of this doc
In your gwt project, go to properties, Java build path, source, click "link source" and point to your non-gwt project source package that you wish to include.
Edit: Found a eclipse fix. Run config > Classpath > Advanced > Add folder > otherproject/src .
Reason: Eclipse adds the bin folders of exported projects. GWT needs the src folders.
Elaborating on my comment.
I am using gwt 2.8 on Eclipse Neon, Java 1.8.0_92. Referring to another project in eclipse fails to launch devmode, because it cannot find the source for referred files from the other project.
What worked:
Switched to 'ant devmode' completely. Made the following changes to build.xml:
<target name="gwtc" ...>
<java ...>
<classpath>
<pathelement location="src"/>
<pathelement location="../otherproject/src"/><!-- Added -->
...
...
<target name="devmode" ...>
<java ...>
<classpath>
<pathelement location="src"/>
<pathelement location="../otherproject/src"/><!-- Added -->
Now do a production build with 'ant' or start devmode with 'ant devmode'.
Other things I noticed
Using the method in the accepted answer, otherproject/src/foo.gwt.xml is picked up (complains if not available), and static values from classes are picked up. Nothing else is. Very weird.
I understand that the DevMode/gwtc executables pick up sources from their class path. So all that is needed is for eclipse to add referred projects to their class path. I was not able to achieve this but this seems possible. FIXED see top.

Is there a quick way to export a WAR file in Eclipse 3.4?

I know about the export->war file
I would like something similar to the .jardesc that allows you to define the destination. So I could right-click on that .jardesc and do export. Except .wardesc instead of .jardesc :)
Is the war export functionality tied to an eclipse ant task?
I've put together an AHK macro so it will do the GUI motions for me... but that's a hack not a solution.
Is the war export functionality tied to an eclipse ant task?
As far as I know, yes. You might try searching for a plugin that can do this for you; I found a couple, such as the war-plugin builder, but I haven't tried it myself, as I try to avoid using extra plugins in eclipse.
Theres the Ant WAR task.
Eclipse has the notion of external commands. If you can write e.g. an ant script that does the export the way you like it you can start it from the menu/button. For ant scripts you can also pick the ant target you want to call and pass properties. This allows you to edit e.g. the path name in the Launch Configuration.
The right way to do "war export" is to use a build system (like Maven) and let it do the heavy lifting. All you need is a pom.xml with <packaging>war</packaging>.
Eclipse's exports are meant for occasional exports by humans, not for automation. And if you would really like to automate, do it right. You will benefit from other things, too. The same pom file will run on your machine, on other developers' machines and on your build server.
WAR ant task
http://ant.apache.org/manual/Tasks/war.html
from the documentation:
Assume the following structure in the project's base directory:
thirdparty/libs/jdbc1.jar
thirdparty/libs/jdbc2.jar
build/main/com/myco/myapp/Servlet.class
src/metadata/myapp.xml
src/html/myapp/index.html
src/jsp/myapp/front.jsp
src/graphics/images/gifs/small/logo.gif
src/graphics/images/gifs/large/logo.gif
then the war file myapp.war created with
<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
<fileset dir="src/html/myapp"/>
<fileset dir="src/jsp/myapp"/>
<lib dir="thirdparty/libs">
<exclude name="jdbc1.jar"/>
</lib>
<classes dir="build/main"/>
<zipfileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
will consist of
WEB-INF/web.xml
WEB-INF/lib/jdbc2.jar
WEB-INF/classes/com/myco/myapp/Servlet.class
META-INF/MANIFEST.MF
index.html
front.jsp
images/small/logo.gif
images/large/logo.gif