Is there a way to add a dynamic library folder to a plain Java project similar to WEB-INF/lib in a Dynamic Web Project?
I mean, can I specify a simple folder, let's just call it lib, and have Eclipse monitor it for any library jars I might want to add or remove.
Currently I only know this behaviour from the Web App Libraries where any jar you copy into WebContent/WEB-INF/lib is automatically added to the class path, but in "regular" Java Projects I need to add every jar by hand.
Yes and no. It requires writing a suitable extension to the org.eclipse.jdt.core.classpathContainerInitializer. If you're in the Package Explorer, though, you can just select all the jars within the View and use the context menu to add/remove them to/from the Java Build Path.
Related
I'm wanting to use some java code as a reusable component jar in my GWT 2.4 application.
I need access to that code on the client side, so I've read that the steps involved are to
add an entry in the main projects gwt.xml file pointing to this project,
include a gwt.xml file in the jar
and put the java code under a client folder.
I assume that this has to be a gwt project itself, otherwise there would be no need to add the inherits entry or is it not possible to use a regular java project client-side?
Is there anything else I need to do for this (other than ensure the libraries in the jar fall under the JRE Emulation Reference list)?
We don't use the plugin functionality in Eclipse, but to use another project in your GWT project all you need to do is define a .gwt.xml module file in your project that you want to use in your GWT project and reference that module file with <inherits.../> in your main GWT project. You will also obviously need to add that project as a reference in the build path in Eclipse, so you don't get compilation errors. And all of that is besides the fact that your referenced project has to comply to the JRE emulation reference so it can be fully GWT compilable.
Is there a way to split up a Dynamic Web Project in Eclipse into two libraries and link them up properly?
So, I'd like to have a library project and two other applications specific web projects. Both using the library project.
I looked into the "references" option in Eclipse to link projects up but didn't work as intended. I also looked into Web Fragment feature but that didn't let me define servlets which need to be defined in the lib project as well as the servlets will be the same for both projects.
Also, is there a way to overlay content from the lib project by content defined in each project? Example:
-Lib
-WEB-INF
-img.jpg
-AppProjectA (using Lib project)
-WEB-INF
-img.jpg
I'd like to be able to use the Lib project in AppProjectA and replace the img.jpg file imported from the lib project with the one defined in AppProjectA.
I looked into Maven overlay but that's a bit too crazy for what I need to do. I also prefer Ant script over Maven. Any ideas on how to accomplish what I need to do here?
I guess with sufficiently clever Ant you probably can achieve what you want, but I don't know of anything off the shelf. However do you really need to do this? Can you get the level of reuse by just referring to resources from the other web app?
Suppose you deploy them both, each with their own context root.
A page from appA can refer to appB
/appB/imgages/img.jpg
For common code, put it in a library JAR project, packaging the JAR in the root of the EAR, or in WEB-INF/lib of each app.
I have "myUserLib.userlibraries" file with all the required user libraries defined. As part of my plug-in that i developed (this will create web projects and required settings), i want to import this file to the projects created by the plug-in.
Is there any programatic way to import libraries from a file?
If you are developing a plugin to add these libraries to project classpath, I recommend that you consider writing a custom classpath container rather than re-using the user libraries facility. If you write a custom container, project classpath would include id of your container and JDT will query your code at runtime to get the actual list of classpath entries.
This will save you from having to store and maintain the contents of your library in workspace preferences, as you would have to do if you took the user library approach.
See org.eclipse.jdt.core.IClasspathContainer class.
Finally i got this worked the way i want. I am now able to programmatically upload the userlibraries into workspace preferences from "myuserlibs.userlibraries" file. I used following eclipse plugins classes.
org.eclipse.jdt.internal.core.UserLibrary.class
org.eclipse.jdt.internal.core.UserLibraryManager.class
org.eclipse.jdt.internal.core.UserLibraryClasspathContainer.class
org.eclipse.jdt.internal.core.UserLibraryClasspathContainerInitializer.class
These classes have bunch of methods to achieve this task.
Once they got uploaded in to preferences, i am also able to programmatically add required user library entries into a respective projects (created by my plugin). Because i have around 8 web projects in my workspace and all of them required different set of user libraries in their classpath container.
I'm a bit confused with NetBeans (versions 6.5 and 6.7). I have a NetBeans Module Suite application, which consists of several NetBeans Modules. I need to add some code in one of the modules. The new code is using a library, distributed as several jar files.
The problem is, that NetBeans does not allow me to add this library jars directly to the classpath. It wants to wrap all the jars in a new Library Wrapper Module, which is then added to the project and used from there. The effect is that all the original jars are combined into a single new jar automatically by NetBeans. This is a problem, because I can't just replace the jars later, without rebuilding this "Library Wrapper Module" and the original library is updated nightly.
I read some NetBeans forums, but I found nothing... I tried with simple java application, where it is possible to simply add jar(s) to the classpath using Project Properties -> Libraries -> Add JAR/Folder. If you use a NetBeans module instead of a simple application, the Libraries dialog looks different and does not have the "Add JAR/Folder" button.
Is it possible to add a plain normal jar in a NetBeans module and how?
It looks like the way a user can wrap a jar has changed in NetBeans 6.8.
Since this has been integrated into a property dialog of a project, the build process might be smarter, too. And it seems like that was your primary concern....
I'm using Netbeans IDE for developing a web applications, and I've some JARs available in the application server which don't need to be in the WAR (but we need them to compile and run locally).
Is there an option in Netbeans to exclude the JAR file while building the WAR file?
Select the project in the Projects explorer window.
Pick the Project Properties item from the File menu (up in the menubar).
Select the word Libraries from the list on the lefthand side of the dialog that appears.
For each jar/library listed in the Compile-time Libraries list, uncheck those that do not need to be included in your war file.
I found the problem myself. I've all the libraries under my lib folder and added them to the project class path. Since the build is copying the entire content in the project, my library is also copying even though I've unchecked the package check box against the library.
So, don't put the library in your lib folder if you want to exclude that in the WAR built.
Thanks
Santhosh