Compiling javah in eclipse(jni)

hi all,
i m writing a java code to access c++ dll files.
I have written the java class and save it with hello.java.
i dont know how to compile it with the javah and -jni.
I am using eclipse. i have also downloaded cdt tool.
also if there is an easy way to generate jni file for the c++, that would save my time.
as i want to save my time.
providing solution would be so nice of you.
best regards

It sounds like you may have misconceptions about JNI. Have you done any JNI tutorials? Start simple - until you know how something works, tools aren't going to be very easy to use.
This one may help:
http://codequirks.blogspot.com/2008/06/introduction-to-jni.html

Similar Messages

  • How to compile a dll for JNI in the CMD correctly

    Now I find alot of old threads on using the mno command in cygwin to created dlls to use as an interface between c and Java, however I know this command is no longer available in cygwin and so I took the advid of downloading minGW and using this in the CMD instead.
    However every example I try to compile and run this way throws the unsatified link error when the native function is to be called by the Java program. I believe it must be a compiling error creating a mismatch between the native function and the function to be called.
    Here is the method I'm using to comile dlls for JNI, it is from the FAQ section of the minGw website:
    gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at
    -Ic:/j2sdk1.4.1_02/include -Ic:/j2sdk1.4.1_02/include/win32
    -shared someJavaImp.c -o JavaImp.dll
    Is this how dll should be compiled? If not any suggestions?

    sudsey wrote:
    I know how to program well in C and Java, I just need to know the proper way to compile a dll for JNI.1. Get the MS IDE
    2. Create a dll project - it must NOT be a managed dll
    3. All done.

  • Problem in compiling C file with JNI

    Hello to all,
    I have a simple JNI tutorial
    But after creating the header file using "javah -jni " command when I use that header file in to the C implementation it gives error
    Following code is of HelloWorld.cpp in which the header file in included
    #include <stdio.h>
    #include "HelloWorld.h"
    JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
         printf("Hello World!\n");
         return;
    }The error is
    line number 2 - Unable to open include file "HELLOWORLD.H"
    line number 4 - Declaration syntax errorMy java file "HelloWorld.java" is
    class HelloWorld
         private native void print();
         public static void main(String[] args)
              new HelloWorld().print();
         static
              System.loadLibrary("HelloWorld");
    }I also after coping the file into the include directory of the TurboC but same error arise.
    Please suggest me what to do.
    Thanks in advance

    Yes I used "javah -jni HelloWorld" command after complying the program.
    It produced a header file which I have placed in the same directory in which my project is. Then the same error comes, when I place it in include directory of TurboC give same error.

  • Compilation problem in Eclipse 3.0/ Fedora Core 3

    Hello,
    I have an eclipse project which just now started to give me this problem.
    When I run a class, I get the error
    Exception in thread "main" java.lang.NoClassDefFoundError: [class name]
    When I look in the folder where the java file resides, no class file has been generated so
    its no surprise that the error has been thrown.
    However, if I create a new project from scratch everything runs smoothly.
    Does anyone have any ideas/solutions.
    Regards
    Thomas

    sometimes eclipse does run into problems compiling a project, you can try:
    Project -> Clean... to rebuild the project from scratch.
    When I look in the folder where the java file
    resides, no class file has been generated so
    its no surprise that the error has been thrown.did you setup the project to have separate folders for src and bin?

  • Compiles well with eclipse but not with javac

    Hello.
    I am using Windows XP and eclipse 3.0.2.
    I have j2sdk-1_4_2_07-windows also.
    I built class files from the code below with eclipse.
    On jre, It silently runs and exits as expected.
    But when compiled with javac, It does not.
    It dumps a stack trace.
    Which compiler is right?
    public class ANullPointerException {
         private Object o = new Object();
         private Sub sub = new Sub();
         private abstract static class Super {
              protected abstract Object access();
              private Super() {
                   access();
         private class Sub extends Super {
              protected Object access() {
                   return o;
         public static void main(String[] args) {
              new ANullPointerException();
    }the stack trace was as below
    java.lang.NullPointerException
         at ANullPointerException.access$200(ANullPointerException.java:1)
         at ANullPointerException$Sub.access(ANullPointerException.java:15)
         at ANullPointerException$Super.<init>(ANullPointerException.java:9)
         at ANullPointerException$Super.<init>(ANullPointerException.java:5)
         at ANullPointerException$Sub.<init>(ANullPointerException.java:13)
         at ANullPointerException$Sub.<init>(ANullPointerException.java:13)
         at ANullPointerException.<init>(ANullPointerException.java:3)
         at ANullPointerException.main(ANullPointerException.java:20)
    Exception in thread "main" I found 3 class files built by eclipse. They were
    ANullPointerException$Sub.class,
    ANullPointerException$Super.class and
    ANullPointerException.class.
    No missing or extra files found, I think.
    But I found 4 class files built by javac. They were
    ANullPointerException$1.class,
    ANullPointerException$Sub.class,
    ANullPointerException$Super.class and
    ANullPointerException.class.
    I do not know why ANullPointerException$1.class is needed.
    Thank you in advance.

    I found the answer myself.
    I have been setting the eclipse's .class file compatibility to 1.4.
    But it is not javac's default.
    So all I need to do is javac -target 1.4 ANullPointerException.java.
    Sorry for a noise

  • Compile problem when using JNI in c program.

    I am run JDK 1.4 on AIX 5.1. I am trying to compile following code.
    #include <jni.h>
    main() {
    JNIEnv *env;
    JavaVM *jvm;
    JDK1_1InitArgs vm_args;
    jint res;
    jclass cls;
    jmethodID mid;
    jstring jstr;
    jobjectArray args;
    /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
    vm_args.version = 0x00010001;
    JNI_GetDefaultJavaVMInitArgs(&vm_args);
    res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
    if (res < 0) {
    fprintf(stderr, "Can't create Java VM\n");
    exit(1);
    cls = (*env)->FindClass(env, "Prog");
    if (cls == 0) {
    fprintf(stderr, "Can't find Prog class\n");
    exit(1);
    mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V");
    if (mid == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(1);
    jstr = (*env)->NewStringUTF(env, " from C!");
    if (jstr == 0) {
    fprintf(stderr, "Out of memory\n");
    exit(1);
    args = (*env)->NewObjectArray(env, 1,
    (*env)->FindClass(env, "java/lang/String"), jstr);
    if (args == 0) {
    fprintf(stderr, "Out of memory\n");
    exit(1);
    (*env)->CallStaticVoidMethod(env, cls, mid, args);
    (*jvm)->DestroyJavaVM(jvm);
    I run this command command and get the following errors
    gcc invoke.c -o invoke -I/usr/java14/include -I/usr/java14/jre/bin -L/usr/java14/jre/bin -Lusr/java14/jre/bin/classic/
    ld: 0711-317 ERROR: Undefined symbol: .JNI_GetDefaultJavaVMInitArgs
    ld: 0711-317 ERROR: Undefined symbol: .JNI_CreateJavaVM
    I think I having all the location for the correct libraries or am I missing one.

    You must include the aix sub-folder and the main include folder:
    -I/usr/java14/include/aix -I/usr/java14/include
    (No need to include the bin folder)

  • "Java file" & "Jsp file" compilation issues in Eclipse

    Hi,
    Eclipse
    Question 1:
    I have set the value for preference->java->Installed JREs as : j2re1.4.2_07 not to jdk
    When I write a java file, its compiling, how? From where its using "javac" exe file for compilation.
    Question 2:
    Whereas in prefrence->Tomcat->JVMSettings -> JRE(drop down box) set value as j2re.1.4.2_07
    When I write a jsp file as follows
    index.jsp
    <html>
    <body>
    <%java.util.Date d = new java.util.Date();%>
    Todays date is <%= d.getDate()%> and this jsp page worked!
    </body>
    </html>
    when i try to save this file & strat tomcat I got exception as follows:
    Exception:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: -1 in the jsp file: null
    Generated servlet error:
    [javac] Compiling 1 source file
    Please clear my doubts.
    Thanks,
    Hari

    Try going into your TOMCAT_HOME/conf/web.xml and look for this section:
    <servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
    <param-name>logVerbosityLevel</param-name>
    <param-value>WARNING</param-value>
    </init-param>
    <init-param>
    <param-name>fork</param-name>
    <param-value>false</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
    </servlet>
    Change the <param-value> for fork from false to true and see if that helps.
    Otherwise it's a problem with your JSP.

  • Compiling servlet in Eclipse SDK

    Why Eclipse cannot find javax.servlet.* and javax.servlet.http.*?
    Here is a screenshot:
    http://ftf-111.yousendit.com/download/1/0C8661815429FB0F/3a9aafda2ce24bfddee6d37aa7a9df8e8bbf98dc/servlet_error-vi.jpg

    do you just want to compile it or deploy it on a server as well? compiling usually isn't the problem, since it's just a simple class as any other.
    if you want it assembled as a deployable web-application you will need ant (war-task) or a plugin like lomboz or myeclipseide to do that for you.
    hope that helps.

  • Unable to compile application in eclipse

    Please help me compile and run a servlet HelloWorld project in Eclipse.
    I am trying to compile a sample helloWorld Servlet in Eclipse 3.x Europa and Tomcat 6. When I click on Run a window comes up asking do I want to run it as a java application or Applet. If I selet Applet, it said that there is no applet avaible. If I select Java Application is will ask to select an item from the list. The following three items appeasr in a list
    jspC �
    SDCInstaller -
    SmapGenerater �
    If I go to projec to build the class, it is grey out. However, the option Build Automatically is checked.
    If I look in my working directory, I can see a blank bin, src, and work folder. In the WEB-INF directory, I see a empty lib, the scr has the HelloWorld.java, and the class has the Helloworld.class. Please Help me!!!

    Thanks,
    I was able to compile it. First, I start tomcast, and I stop it right away. Then, I click on run, and it run it. However, I am getting the error message. I think it may have to do with the xml file that I am using. I notice the web-app and servlet name are hilight as if they were spelled wrong. If I change web-app to WEB-APP, it does not show me the error but it does not work either. Below is a copy of my web.xml file and the error message that I am getting when I type the url http://localhost:8080/HelloWorld/hello
    " type Status report
    message This application is not currently available
    description The requested service (This application is not currently available) is not currently available.
    Also, I see an exeption in the application see below the class file
    <strong > -- XML FILE </strong>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd"> -->
    <web-app>
    <servlet>
    <servlet-name>Hello</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping>
    </web-app>
    <strong> class </strong>
    import java.io.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    public class HelloServlet extends HttpServlet {
    public void doGet (HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException, IOException
    PrintWriter out = res.getWriter();
    out.println("Hello, Brave new World!");
    out.close();
    <strong > error Message </strong>
    Jan 10, 2008 10:52:02 AM org.apache.catalina.core.AprLifecycleListener init
    INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_14\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jre1.6.0_03\bin\client;C:\Program Files\Java\jre1.6.0_03\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.5.0_14\bin;C:\JDBC\sqljdbc_1.2\enu\sqljdbc.jar;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Tomcat;C:\Tomcat\bin;C:\eclipse\Workspace;c:/.;C:\Tomcat\lib\servlet-api.jar;C:\Tomcat\lib\jsp-api.jar
    Jan 10, 2008 10:52:02 AM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8080
    Jan 10, 2008 10:52:02 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 896 ms
    Jan 10, 2008 10:52:02 AM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Jan 10, 2008 10:52:02 AM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
    Jan 10, 2008 10:52:02 AM org.apache.tomcat.util.modeler.Registry registerComponent
    SEVERE: Null component Catalina:type=JspMonitor,name=jsp,WebModule=//localhost/HelloWorld,J2EEApplication=none,J2EEServer=none
    Jan 10, 2008 10:52:02 AM org.apache.catalina.startup.HostConfig deployDescriptor
    SEVERE: Error deploying configuration descriptor HelloWorld.xml
    java.lang.UnsupportedClassVersionError: Bad version number in .class file
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1817)
         at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
         at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
         at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
         at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
         at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1064)
         at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4239)
         at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
         at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
         at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
         at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
         at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
         at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
         at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
         at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
         at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
         at org.apache.catalina.core.StandardService.start(StandardService.java:516)
         at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
         at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Jan 10, 2008 10:52:03 AM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Jan 10, 2008 10:52:03 AM org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    Jan 10, 2008 10:52:03 AM org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/31 config=null
    Jan 10, 2008 10:52:03 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 1348 ms
    Jan 10, 2008 10:52:13 AM org.apache.tomcat.util.modeler.Registry registerComponent
    SEVERE: Null component Catalina:type=JspMonitor,name=jsp,WebModule=//localhost/HelloWorld,J2EEApplication=none,J2EEServer=none
    Jan 10, 2008 10:52:13 AM org.apache.catalina.startup.HostConfig deployDescriptor
    SEVERE: Error deploying configuration descriptor HelloWorld.xml
    java.lang.UnsupportedClassVersionError: Bad version number in .class file
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1817)
         at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
         at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
         at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
         at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
         at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1064)
         at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4239)
         at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
         at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
         at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
         at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
         at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
         at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
         at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1206)
         at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
         at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
         at java.lang.Thread.run(Thread.java:595)

  • Source code doesn't seem to line up with the compiled classes in ECLIPSE

    I am trying to write a Tomcat servlet to parse an incoming message, however when I parse the message to get the parts out of it I get a a parse error that doesn't really tell me a lot.
    I have downloaded the source code for the Java Mail API 1.3.2 and attached it to the jar file in Eclipse.
    However when I debug the code and step through it I get two problems. 1) I get a warning that I can't see the local variables (not really a great problem). 2) The lines in the source code do not line up with where the stack says I am.
    I have checked the dates on the various classes and the source of the API and they seem to line up.
    I did try to recompile the classes just as an experiment but I am runing JDK_1.4.2_06 and the source seems to be set up for 1.5 and I have some missing classes. I can't switch to 1.5 because there are some other servlets running on this server that won't work on 1.5.
    Can anyone give me a clue how I can at least get the the correct line number.
    Thanks
    Brynn

    Has anyone any ideas on this please?

  • Sun ONE - compile OK, disaster follows; Eclipse - compile fails

    I hope Sylvia won't rap my knuckles with her ruler for posting an "it won't compile" message here, but this one is more than a bit strange.
    I was running Sun ONE Studio. It compiles my program w/o errors; then the application runs and crashes my Windows Me computer. Reliably; repeatedly. Hard to make progress when your development cycle is compile, try to test, reboot. What to do?
    Maybe the problem's in S1S! Try Eclipse. It won't compile the program. It says:
    java.lang.Error: Unresolved compilation problem:
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at jdb.FileViewer.main(FileViewer.java:120)
    Exception in thread "main"
    Come to think of it, that's really a compile error detected at run time, isn't it? Didn't know that was possible. Anyway, the offending line is:
      public static void main( String[] args ) {}(I simplified main() a bit trying to track this down.) If I remove main() altogether, it compiles and dies with the expected "can't find main()" error.
    Anybody can make any sense of this? (BTW, kudos to Eclipse. This beats trashing my machine. There's nothing but java here - no JNI - so trashing the OS isn't even possible, is it? So much for theory.)

    Maybe the problem's in S1S! Try Eclipse. It won't
    compile the program. It says:
    java.lang.Error: Unresolved compilation problem:
    (snipped)
    Exception in thread "main" Er... where exactly does Eclipse tell you this? Normally compilation diagnostics show up in the Task View. The above stack trace looks like nothing I have ever seen before when compiling. What Eclipse view is showing this message?
    Anybody can make any sense of this? (BTW, kudos to
    Eclipse. This beats trashing my machine. There's
    nothing but java here - no JNI - so trashing the OS
    isn't even possible, is it? So much for theory.)Eclipse uses SWT which is a native library. So theory is still valid, I guess.

  • Generic working in eclipse compiler but not through builds

    The following code snippet works fine in my eclipse development environment (1.6.0_06), but the build system running 1.6.0_06 throws exception:
    MyClass:343: incompatible types
    found : java.util.List<C>
    required: java.util.List<B>
    entries = createListFromSmartCopy(myAList, new B(), true);
    Types:
    A is an interface
    B is an interface of A
    C is an implementation of B
    List<A> aList = new ArrayList<A>();
    aList.add(new A());
    List<B> return = createListFromSmartCopy(aList, new C(), true);
        * <p>Creates a copy of a list where the source list could be an ancestor
        * type of the returned list. It also uses a reference object to actually
        * construct the objects that populate the return list.</p>
        * @param <T> - The ancestor type of the source list
        * @param <R> - The derived type of the destination list
        * @param <S> - The more derived type of the prototype object used to
        * construct the list of R's
        * @param sourceList - The source list
        * @param referenceObject - The object used to construct the return list
        * @param deepCopy - Deep copy serializable objects instead of just copying
        * the reference
        * @return a list of R's (as defined by the caller) of entries with the
        * object constructed as a copy of referenceObject with the properties of the
        * sourceList copyied in after construction
    public static <T extends Serializable, R extends T, S extends R> List<R> createListFromSmartCopy(
                List<T> sourceList, S referenceObject, boolean deepCopy)
          List<R> retr = new ArrayList<R>();
          for(int i = 0; i < sourceList.size(); i++)
             retr.add(copyOf(referenceObject));
             copyInto(sourceList.get(i), retr.get(i), deepCopy);
          return retr;
       }Any thoughts on either:
    1. How does this pass the compiler validation inside eclipse, even through 'R' has not been defined? I believe that the code is doing some sort of return type inference to return the exactly correct type of list as referred by the return result or else it is simply ignoring the invariant capture of R all together and silently dropping the error. The funny thing is that the code does work just fine in practice in my development system without an issue.
    or
    2. Why if the code is valid does the independent build system disallow this generic return type 'inference' to occur? Are there compiler flags I can use to withhold this special condition?

    Thanks for the response, I wasn't trying to show a full example but just my implementation's snippet. I'll list one now:
    package test;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    public class TestMe
        * <p>This method performs a deep copy of an object by serializing and
        * deserialzing the object in question.</p>
        * @param <T> - The type of data to copy
        * @param original - The original object to copy
        * @return The object who's state should be the same as the original. This
        * call uses serialization to guarantee this copy is fully separate from the
        * original, so all sub-object references are also deep copies of their
        * originals
       @SuppressWarnings("unchecked")
       public static <T extends Serializable> T clone(T original)
          T obj = null;
          try
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
             ObjectOutputStream out = new ObjectOutputStream(bos);
             out.writeObject(original);
             out.flush();
             out.close();
             ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
                      bos.toByteArray()));
             obj = (T)in.readObject();
          catch(IOException e)
             e.printStackTrace();
          catch(ClassNotFoundException cnfe)
             cnfe.printStackTrace();
          return obj;
        * <p>Copies the properties from one object to another. The destined object
        * in this method must be derived from the source object. This allows for a
        * faster and smoother transition.</p>
        * @param <T> The type of source
        * @param <R> The type of destination
        * @param source - The source object
        * @param destination - The destination object
        * @param deepCopy - Copies the reference objects instead of just passing
        * back the reference pointer reference
       public static <T, R extends T> void copyInto(T source, R destination,
                boolean deepCopy)
       // Stubbed because it links into a ton of unnecessary methods
        * <p>Copies the values of a list of an ancestor class into the values of
        * another list who's value is derived from the ancestor.</p>
        * @param <T> - The ancestor type of the source list
        * @param <R> - The derived type of the destination list
        * @param sourceList - The source list
        * @param destinationList - The destination list
        * @param deepCopy - Deep copy serializable objects instead of just copying
        * the reference
       public static <T, R extends T> void copyIntoList(List<T> sourceList,
                List<R> destinationList, boolean deepCopy)
          if(sourceList.size() > destinationList.size())
             throw new IllegalArgumentException(
                      "Cannot copy entire source set into destination list");
          for(int i = 0; i < sourceList.size(); i++)
             copyInto(sourceList.get(i), destinationList.get(i), deepCopy);
        * <p>Creates a copy of a list where the source list could be an ancestor
        * type of the returned list. It also uses a reference object to actually
        * construct the objects that populate the return list.</p>
        * @param <T> - The ancestor type of the source list
        * @param <R> - The derived type of the destination list
        * @param <S> - The more derived type of the prototype object used to
        * construct the list of R's
        * @param sourceList - The source list
        * @param referenceObject - The object used to construct the return list
        * @param deepCopy - Deep copy serializable objects instead of just copying
        * the reference
        * @return a list of R's (as defined by the caller) of entries with the
        * object constructed as a copy of referenceObject with the properties of the
        * sourceList copyied in after construction
       public static <T extends Serializable, R extends T, S extends R> List<R> createListFromSmartCopy(
                List<T> sourceList, S referenceObject, boolean deepCopy)
          List<R> retr = new ArrayList<R>();
          for(int i = 0; i < sourceList.size(); i++)
             retr.add(clone(referenceObject));
             copyInto(sourceList.get(i), retr.get(i), deepCopy);
          return retr;
       public static void main(String[] args)
          List<A> aList = new ArrayList<A>();
          aList.add(new AImpl());
          aList.add(new AImpl());
          List<B> bList = createListFromSmartCopy(aList, new C(), true);
          for(B bItem : bList)
             System.out.println("My String = "
                      + bItem.getString() + " and my number = " + bItem.getInt());
       public static interface A extends Serializable
          public void setString(String string);
          public String getString();
       public static class AImpl implements A
          private static final long serialVersionUID = 1L;
          @Override
          public void setString(String string)
          @Override
          public String getString()
             return null;
       public static interface B extends A
          public void setInt(int number);
          public String getInt();
       public static class C implements B
          private static final long serialVersionUID = 1L;
          public C()
          @Override
          public String getInt()
             return null;
          @Override
          public void setInt(int number)
          @Override
          public String getString()
             return null;
          @Override
          public void setString(String string)
    }In my eclipse (20090920-1017), this compiles and runs just fine. I stripped out the functional pieces that weren't pertinent to the discussion.

  • Eclipse -- jDeveloper   ((why wont jsp compile))??

    Error(6,20): Attribute 'xmlns:xalan' used but not declared.
    Above error is given.... the xalan.jar in my class path..., but it still doesn't work..
    I have a project that compiles great in Eclipse v3.0 but when I import the war into jDev i get several errors when compiling JSP's that use struts tag libraries.
    (I thought migrating war's would be easier than this)
    Pls help!!
    Don Lykins

    The xalan namespace attribute is used in a Stylesheet.
    xmlns:xalan="http://xml.apache.org/xalan"Are you using taglibs?
    If the <taglib> element in a tld has the xmlns:xalan attribute, remove the xmlns:xalan attribute.

  • Compiling JNI library with resource files (i.e. images)

    hi-
    i'm compiling a jni library on mac osx leopard using a command like:
    cc -g -dynamiclib -o libJNI.jnilib file1.o file2.o main.o -framework JavaVM -framework Foundation -framework AppKit -framework Cocoai'd like to include resource files like images in the build of the jni library. how can i compile those into the jni library?
    thanks,
    augusto.

    Creating shared libraries themselves are compiler/linker/OS problems.
    Not Java/JNI.
    So finding a forum that answers questions about the compiler/linker in use is the place to ask them.

  • Compiling with external JARs using Eclipse

    I've spent 3 days on this and I still don't seem to be any nearer solving the problem. I am using a couple of external JAR files within my project and everything is working fine within the IDE, it's when I come to compile my own JAR that I'm having problems. I've tried created my JAR by choosing file->export, but it doesn't seem to pull in the external JARs. My class paths must be correct as I can run it within the IDE, but I'm missing something.
    Next I discovered ANT and had a play with that. After some toil I got it to generate a JAR, but it has two problems. 1. The manifest file cannot be found, but let's forget about that for now, as I haven't really looked into it. 2. The generated JAR is only 250Kb, when (if the external JARs are packaged with it) it should be closer to 5Mb. Again I've set my class paths in the External Tools dialog, but still nothing.
    Could someone please try and point me in the right direction. I've even spent a couple of hours at Borders reading up on ANT and Eclipse, that where my ANT script came from, but it hasn't got me the result I need. If it's any help my build.xml is below
    <?xml version="1.0" encoding = "UTF-8"?>
    <project name="C_G" default="Main Build" basedir=".">
        <property name="bin" location="bin"/>
        <property name="src" location="."/>
        <property name="jardir" location="${bin}/lib"/>
        <property name="jarfile" location="${jardir}/c_g.jar"/>
        <property name="build.compiler"
        value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <target name="Main Build" depends="Initialize, Compile, Jar">
            <echo message="Ant Building"/>
        </target>
        <target name="Initialize">
            <delete dir="${bin}"/>
            <delete dir="${jardir}"/>
            <mkdir dir="${bin}"/>
            <mkdir dir="${jardir}"/>
        </target>
        <target name="Compile" depends="Initialize">
            <javac srcdir="${src}"
                destdir="${bin}">
            </javac>
        </target>
        <target name="Jar" depends="Initialize, Compile">
            <jar destfile="${jarfile}" basedir="${bin}"/>
        </target>
    </project>

    Damn it, so I do have to tackle the 'manifest not
    found problem' first then. I would have though
    Eclipse would have made a better job at making the
    manifest file.All I can say: RTFM. This is not an Eclipse support forum. Maybe it does, and you use some incorrect settings.
    I just placed it into the root of the JAR, but when I
    run it can't find itIt doesn't belong there. It goes into a directory named META-INF

Maybe you are looking for