I wish to write a shared library to be used in various GWT applications. The shared library will leverage GWT APIs and should not be able to use non-emulated Java classes.
Two questions:
Is there a plugin for Eclipse that will let me use GWT APIs and flag if I use a non-emulated class (but will simply build a compliant jar rather than a war)? (I know that the standard plugin does this when working in the 'client' area, I just want the same behaviour for the entire source tree)
If not, is there a Maven/Ant plugin that will help?
For a GWT library, you have to include a GWT module (*.gwt.xml file) and the *.java files in your *.jar (or in a distinct JAR if you prefer).
AFAIK, the Google Plugin for Eclipse uses the information from the *.gwt.xml files, the client subpackage is not hard-coded; so you should be able to use it the same way as with a GWT application.
Finally, you can call the GWT compiler with the argument -validateOnly to check that your GWT module uses only translatable classes.
I am pretty sure that you can't develop a gwt shared library and pack it into a jar file. Gwt require access to all source code when compiling files. It can't read class files at all. Or have I misunderstood what you are trying to do?
Related
Let's say you create a new project, and want it to make use of some 3rd party library, say, widget.jar. Where do you add this JAR:
File >> Project Properties >> Libraries >> Compile-Time Libraries; or
File >> Project Properties >> Libraries >> Run-Time Libraries; or
Tools >> Libraries (Library Manager) >> Library Classpath; or
Tools >> Java Platforms (Java Platform Manager)
All of these dialogs seem to do the same thing but I'm sure they all have their proper usages. Can't find a good "best practices" article online and the NetBeans Help Contents dialog isn't helping with this either.
Right click 'libraries' in the project list, then click add.
You want to add libraries to your project and in doing so you have two options as you yourself identified:
Compile-time libraries are libraries which is needed to compile your application. They are not included when your application is assembled (e.g., into a war-file). Libraries of this kind must be provided by the container running your project.
This is useful in situation when
you want to vary API and implementation, or when the library is supplied by the container (which is typically the case with javax.servlet which is required to compile but provided by the application server, e.g., Apache Tomcat).
Run-time libraries are libraries which is needed both for compilation and when running your project. This is probably what you want in most cases. If for instance your project is packaged into a war/ear, then these libraries will be included in the package.
As for the other alernatives you have either global libraries using Library Manageror jdk libraries. The latter is simply your regular java libraries, while the former is just a way for your to store a set of libraries under a common name. For all your future projects, instead of manually assigning the libraries you can simply select to import them from your Library Manager.
If your project's source code has import statements that reference classes that are in widget.jar, you should add the jar to your projects Compile-time Libraries. (The jar widget.jar will automatically be added to your project's Run-time Libraries). That corresponds to (1).
If your source code has imports for classes in some other jar and the source code for those classes has import statements that reference classes in widget.jar, you should add widget.jar to the Run-time libraries list. That corresponds to (2).
You can add the jars directly to the Libraries list in the project properties. You can also create a Library that contains the jar file and then include that Library in the Compile-time or Run-time Libraries list.
If you create a NetBeans Library for widget.jar, you can also associate source code for the jar's content and Javadoc for the APIs defined in widget.jar. This additional information about widget.jar will be used by NetBeans as you debug code. It will also be used to provide addition information when you use code completion in the editor.
You should avoid using Tools >> Java Platform to add a jar to a project. That dialog allows you to modify the classpath that is used to compile and run all projects that use the Java Platform that you create. That may be useful at times but hides your project's dependency on widget.jar almost completely.
Project Files Services Tabls
go files tabs
drag drop file to libs files hover.
return project tabs and what are you see :)
There are lots of posts about this already but I have not found one that describes my exact situation. Which is:
I have a preexisting build system that generates a C++ shared library in both .dll and .so format (depends on OS).
The build system also produces a set of java files generated by swig.
I also have a pom.xml file that builds the java source into a package.
What I need is a plugin for maven that simply copies the native shared library into the jar. It would be nice if the native shared library was also loadable from within the jar so clients don't have to manually add it to the library path. This seems like a problem that has been solved before.
I have looked at maven-dependency-plugin. Which seems to be able to copy artifacts that are in a maven repository (not my case). Or if you use an assembly it might be possible. However, if it is possible, it seems overly complicated for what I want to accomplish. I would like to accomplish it with only a pom.xml.
I have also looked at nar-maven-plugin, but this seems like it focuses only on building the native library and adding it to a .nar file. This is not what I need since I can already build the C++ library.
Finally, I looked at one-jar which I got to place the native library inside the jar. However, I was not able to import the classes from within that jar, and the clients of this library will expect to be able to do that.
If what I want is possible and I don't need to install the shared library into my local repository please provide a link or an example of how you accomplished it. If it is not possible, please state why.
I am developing an application with many functionality, where one functionality requires a jar file which is only commercially available. When I release it for public use for free, I have to remove this jar file from my source. When I run this application in Eclipse IDE with the jar file removed, it gives me "Errors exist in required Project". I would like to avoid this warning.
Only the users using the library should be able to access its corresponding functionality (The application has many functionality.)
Users who don't include this jar file should be able to access other functionality without any error/warning.
Requirement:
Gray out the functionality based on the absence of the jar file.
Avoid the warning message when I run the Main.java
Any help appreciated. Thanks!
What you need indeed is dynamic class loading, isn't it?
To enable this feature, you have some options:
Implement your own classloader.
Use OSGI.
Additional to yanana's solution, you can simply leave the commercial JAR file in your Eclipse project. When creating your setup you can create one setup for commercial use (including the JAR) and one for the open source version (without the JAR).
But you should be carefully separate the usage of the commercial classes into one or more package/module. At runtime you can check the presence of one class which is part of the commerical JAR file via reflection before accessing code dependent on the commercial JAR.
Your integration tests should contain some corresponding test cases with and without the commercial JAR in classpath.
I've already asked about some similar things connected with theme above and google a lot, but I still can't find exactly what I want, so here we go:
I want to make library, which will use other libraries. I mean some of javacv's .jar's, which we can find here: javacv site
. Some of these libraries are 'normal', some of them contains .dll's. I want to create independent .jar file, which could be use together with above .jars in different projects. Classes in this my .jar file will use methods from javacv's .jars. So my 'independent' library will depend on javacv.
In parallel, I'd like to write application, which will use javacv and my library. So I'd like to create 2 projects:
A) Library, which will depend on javacv 's jar's (I should get here .jar, which could be use in other projects together with javacv)
B) Application which will depend on library from A) and javacv's jars
What should I do in Netbeans (or eventually in Eclipse) to organize it in best way? I know, that I probably should use maven / create some maven projects but I don't know a lot about maven ( I can add... dependency :) ).
I am trying to create a java file from scratch using AST but it is painstakingly taking me longer to finish. What I have in mind is create the java file, then create the project and package and then copy that file to that package. Is there a way to do this?
Thanks.
I use Apache Velocity, in order to create Java classes from templates. In my case, i had to create from (velocity) templates some classes (and maven pom) using Eclipse Wizards. But if you want to modify these classes, then the best choice would be AST/JDT.
http://sdqweb.ipd.kit.edu/wiki/JDT_Tutorial:_Creating_Eclipse_Java_Projects_Programmatically
shows how to create a java project using JDT and configure your classpaths subsequently.
You can use JBoss forge to generate java classes problematically. it has api to write scaffolding plugins. it uses Apache Velocity templates to do that.
Also Spring Roo can be another choice, if you are a Spring guy ;)
IFile#setContents(InputStream ...) would seem like a good candidate.
You can also use the ImportOperation to import files from anywhere (incl. the filesystem outside of the workspace) into a project.