Can I have a Library defined that makes use of JNI in NetBeans?
Seems the library definition only allows Jars or Folders.
How can I assure that the DLL follows the jar file when the app is built?
Assuming you are referring to building a NetBeans Platform App (or module), then you can place the DLL in the "release/modules/lib/" folder. This is per the platform FAQ:
http://wiki.netbeans.org/DevFaqNativeLibraries
Additional information here:
http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
If you are asking more generally, then I think most people package the DLL inside the jar, then extract it to a temp location upon application startup. e.g.
How to make a JAR file that includes DLL files?
If that's not what you're looking for, then you'll need to provide more information as to what you're trying to do.
netbeans won't do it on its own, but since it uses ant behind the scenes there's a workaround.
you should create a subdirectory named jni in your project directory (c:\path\to\mynetbeansproject\jni), put all the .dll, .so and .jnilib files in there (the native stuff), and add the following lines to the build.xml file you find in your project directory, just before the </project> tag:
<target name="-post-compile">
<copy todir="${dist.dir}/lib">
<fileset dir="jni" />
</copy>
</target>
then add the jar file to your project just like you always do. :)
the snippet you inserted in build.xml will make sure that the native libraries follow your jar files in the dist/lib folder when you invoke "Clean and Build" from within netbeans (or ant from the command line); the jvm will look for the .dll (.so, .jnilib) files in the same directory as the .jar that's loading them, so it will work.
note that this won't make your project run from within netbeans, becauseā¦ I'm not really sure what goes on, but it looks like the library path (LD_LIBRARY_PATH) doesn't include your projects' libraries, and there's no way I know of changing it from within netbeans. just put your native libraries in /Library/Java/Extensions on mac os x, or just stash them in c:\windows\system32 under windows. if you're running a 64 bit windows with a 64 bit jvm, I have no clue; if you're running linux, you probably know where to stash them, but /usr/lib/java might be a good bet.
I tested the following solution while using NetBeans 7.0.1 and it worked, but I don't know if it works in early versions, too.
The solution is easy and works per NetBeans module. So, if you have a suite, don't place its JNI files into suite project, instead, place the JNI files that you want into the module itself. Do:
Find a NetBeans module project that you want (or need, or think) to place your JNI libraries (them with extension .DLL, .so and .jnilib, by eg);
At Projects, right click at the module node, click at Properties menu;
In the Project Properties dialog, click at Libraries and Wrapped JARs. You must add any external library there. I added the RxTX jar library. After add your external libraries, the Netbeans Ant script will copy all files/folders from the directory your_project_dir/release to the right location when you build the solution.
So, place your native libraries at your_project_dir/release/lib. If you want, you can create subdirectories for each target platform that you need, as: your_project_dir/release/lib/amd64, your_project_dir/release/lib/sparc32
To know, more, read:
http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
Regards,
marciowb.info
Related
This question is not limited to lex and yacc, but how can I add a custom script compiler as part of a project? For example, I have the following files in the project:
grammar.y
grammar.l
test.script
The binary 'script_compiler' will be generated using grammar.y and grammar.l compiled by lex, yacc and g++. And then I want to use that generated script_compiler to compile test.script to generate CompiledScript.java. This file should be compiled along with the rest of the java files in the project. This setting is possible with XCode or make, but is it also possible with Eclipse alone? If not, how about together with Maven plugin?
(I might setup the script compiler as a separate project, but it would be nice if they can be put in the same project so that changes to the grammar files can be applied immediately)
Thanks in advance for your help!
You can add a custom "Builder" from the project properties dialog. This can be an ant script (with an optional target) or any other script or executable.
There are also maven plugins for ant and other scripting languages
If you just want to run an external program in Maven this is what you want: http://mojo.codehaus.org/exec-maven-plugin/ -- you can then run Maven targets from your IDE or command line and it should do the right thing either way.
To integrate with the normal compilation bind the plugin to the "generate-sources" phase and add the location where the Java files are generated to the "sourceRoot" option of the exec plugin. That way the compiler will pick them up.
Ideally you generate the code into a folder "target/generated-sources/MY_SCRIPT_NAME". That is the standard location for generated sources in the Maven world and e.g. IntelliJ IDEA will pick up source files inside of that location. Note that this doesn't work if the files are directly in "target/generated-sources".
The other option is to write your own Maven plugin, which is actually quite easy as well. See e.g. https://github.com/peterbecker/maven-code-generator
I wanted to move from jboss AS 6 to 7 with hibernate 4 support and now all libraries are in subfolders with module.xml files.
And I have no idea how to add those to my eclipse project build path.
Where do I define my module dependencies?
The easiest way is to do Build Path > Add External Archives and select the jars you want.
Slightly better might be to define a JBOSS_HOME classpath variable, and add the jars as variable entries. That would make things easier if you ever move your JBoss installation.
If you wanted more automation, it would be possible to write a script, for whatever build tool you use, that parses your application's manifest to find which modules it depends on, and add those to your classpath automatically. If you're good at scripting, that should be quite easy.
I am developing JSR 268 compliant portlet and utility with eclipse.
Now, the utility is designed to be a separate JAR from the portlet itself.
Does anyone now how to write an ant build.xml that will
1. Compile and JAR my utility class
2. Move the JAR to the ./lib folder of the portlet
3. Compile and maybe even delpoy the portlet to a tomcat running on localhost?
My biggest problem right now are the build-time dependencies. I dont want to hardcode all the folders as I share this project with two other developers which are on another platform.
Is it possible to reuse the buildpath from eclipse?
Thank you in advance,
Felipe
Does this wizard help
Rigth-click on project -> Export ... -> Ant buildfiles.
?
Though you probably have figured something out by now, for future references I would suggest taking a look at Eclipse's ability to use Ant files as project builders.
An advantage of this is, that will happen automatically as you build and since you only pack and copy the jar file, you don't have to worry about changes in e.g. the class paths, as you would in the two previous answers
Create a ant file that jar the utility project. Follow: [1]
Add it as a ant-builder to your utility project as described in [1]
Now Eclipse will automatically generate the jar file every time you build.
Extend the ant script to also copy to jar file to the lib dir.
Eclipse have ant task to convert workspace/project relative paths to
normal file paths. See [2]. Note that for those tasks to work, you must select ''Run is the same JRE as the workspace'' under the ''JRE'' tab when configuring the ant builder
In order to ensure your utility is build first add a project reference from your portlet to your utility project right click > properties > project references
When you build the following will now happen:
You utility project will build first, because of the project reference
The ant-builder will pack the jar, and copy it to the lib folder.
You portlet project will build using the new jar.
[1] http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2FgettingStarted%2Fqs-92_project_builders.htm
[2] http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/ant_eclipse_tasks.htm
For 1. Just use the and Ant tasks
For 2. Is it on a remote server? How do you get it there? Windows share?
For 3. Set up the Tomcat manager and then use Tomcat's deploy/undeploy Ant tasks:
http://blog.techstacks.com/2009/05/tomcat-management-setting-up-tomcat.html
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />
If you want to avoid hard-coding paths, try to use relative paths. Where are you dependencies right now? What do you feel you may have to specify an absolute path for?
In Eclipse,
Goto Window->preference->Ant->Runtime->Classpath->ant Home
Then add what are the thing u need to add,atlast click ok button to create ant file.
I have a .jar file of LWUIT, and it's also in there in the NetBeans library.
When I add it as a .jar file my programs run good and when I add it as a library my output is not shown correctly. What's wrong with this?
When added as a library, LWUIT is only available for your application to compile against. I assume LWUIT is not already installed on whatever J2ME-enabled device/emulator you want to run your application.
When added to your application JAR file, LWUIT is also available for your application to run against. Your application JAR file is presumably significantly larger then.
I have configured my Eclipse to have a C:\Eclipse\external_libs directory where I place all my external libraries. In my case , my external libs are WATIJ, XMLUNIT, and XOM . Adding the external libs to the project is no problem... there is no question about that.
I also place my JDK at C:\Eclipse\Javasoft .
What I am wondering IS : is there a better location to place external libs? It's important to note that I like being able to pack my Eclipse directory into a zip file and move it and open it on another computer in a portable fashion.
It's normally done on a per app/project basis. For java webapps you normally have your external libs in WEB-INF/lib. However, if you share the libraries across projects AND you need to zip your eclipse directory, what you're doing now is probably the best solution imo.
In linux you could add them to something like /usr/lib/share and include that in your classpath (but you couldn't zip it all up), but not sure if that sort of directory exists in windows.
If you do place all your library in an external folder, please use "linked resources" to avoid putting any fixed path in your .classpath file.
You can then reference that external directory from within your project, with a linked folder.