Adding custom analyzer to Luke - java

This question was already asked here on Stack Overflow, BTW even after reading the answer provided, I do not manage to add MyOwnAnalyzer, so that I can use it directly from Luke.
Please can someone help me on the right way to do, that is how and what to do so that MyOwnAnalyzer can be usable directly from Luke?
Can I do this (it did not work, may be my included jar are incomplete?):
java -cp .;d:\java\mylibs\MyOwnAnalyzer.jar -jar lukeall-3.5.0.jar
(MyOwnAnalyzer.jar was built from Eclipse and contains : MyOwnAnalyzer.java, MyOwnTokenizer.java, and MyOwnToken.java inside a subdirectory com.MyCompany... Eclipse added META-INF and manifest.mf for me)
Maybe I am wrong in adding classpath and MyOwnAnalyzer.jar with my command line?
Or must I build Luke from source including MyOwnAnalyzer somewhere in its directory?
Or is there something else to include/write so that my analyzer can be usable and imported from Luke? (looks like there is a mechanism to detect all classes that subclasses Analyzer - MyOwnAnalyzer is already declared as "extends Analyzer" )
BTW, even if it not really the same question but still in the same topic of using a custom analyzer from Luke... si I have an Error when using the tab Analyzer Tool I get Error analyzing:com/google/common/io/CharStreams , this lib is included in a jar, where I included a main that do a sample analysis to check and everything work fine when using it alone. If I use it as explained by JPountz, from Luke, I can see MyOwnAnalyzer from all the Luke tabs, but it did not work!
from the Luke code source, I think what throw the exception this is located somewhere inside the method analyze.
Note: The call to CharStreams.toString(input); is to transform the Reader input to a String inside MyOwnTokenizer.

Java ignores the -cp option when the -jar option is also used. You need to run Luke this way:
java -cp lukeall-3.5.0.jar;MyOwnAnalyzer.jar org.getopt.luke.Luke

Related

Matlab and JDDE

Update: The problem was solved with the help of MathWorks. I've published the answer below.
I need to control a program (Zemax) from Matlab. Unfortunately, Zemax only supports DDE for such control, which Matlab does not support any more. It works, but stops working on 64 bit platform after a few (presumable 63) DDE calls.
I wonder if there are working solutions. I could probably program a DLL with correct DDE support and then use DDE in Matlab via this DLL. This is a major effort for me. A more suitable solution would be to use Java DDE methods. Following another post here, I've discovered the JDDE library. However I cannot make it work: Even if I am in the directory with the DLL and JAR files, executing
import pretty-tools.JDDE-2.0.3.*
works fine but calling
a = com.pretty_tools.dde.client.DDEClientConversation()
afterwards (as done here) results in
Undefined variable "com" or class "com.pretty_tools.dde.client.DDEClientConversation".
I have very limited writing privileges on my PC, so I have added the javaclasspath.txt file with the jar/dll location to the directory indicated by prefdir. The file looks like this:
C:\Users\xxxxxxxx\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
Calling javaclasspath shows a long listing with the last lines being:
...
C:\Program Files\MATLAB\R2012b\java\jarext\webservices\ws_client_core\mw-service-client-core.jar
C:\Users\kkarapet\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
DYNAMIC JAVA PATH
<empty>
So path seems to be set correctly. What am I doing wrong?
With the help of MathWorks support, I've found the answer. Here is how to make JDDE work with Matlab 2012b, without admin privileges:
Download and unpack JDDE files (DLLs and JAR) into some folder. Let's say it's $path-to-jdde$\.
In Matlab, type prefdir. Open the resulting directory and create two files there, javaclasspath.txt and javalibrarypath.txt.
In javaclasspath.txt, add $path-to-jdde$\pretty-tools-JDDE-2.0.3.jar.
In javalibrarypath.txt, add $path-to-jdde$\.
Restart Matlab.
Now call ddeConv = com.pretty_tools.dde.client.DDEClientConversation; and start using the created object as described in JavaDoc. E.g. to connect to Zemax, run Zemax and then in call ddeConv.connect('Zemax', 'abc').
Step 2 above can only be done starting Matlab version R2012b. With an older version, if you have the write rights on the Matlab installation directory, you should be able to replace step 2 by editing the files librarypath.txt and classpath.txt in $MATLABROOT$\toolbox\local. I could not verify it so if you confirm it please let me know in the comment below.

In eclipse, how can I see where the java classes are loaded from?

My problem is as follow : I am developing an eclipse plugin and sometimes I lose track of where the classes are loaded from. What I would like is to see in the debugger stacktrace where a class is loaded from (which jar on the harddrive).
Am I missing some obvious Eclipse option ?
Any help would be greatly appreciated !
To see location of classes loaded : In Run configurations -> Arguments tab add vm argument -verbose. That will include the full path of classes loaded.
EDIT:
To find a particular class from a list of jars:
I use a jar class finder plugin. I do not recall the exact location from where i downloaded, the alphaworks link seems broken as of now. But you can find similar tools.
Note : In eclipse, if the console fills up to a point you are not able to see previous logs, then in Common tab -> Standard I/O check File option.

Javadoc: Annotations from third party libraries

I'm trying to write an SVN Post-Commit hook to generate javadoc on a webpage whenever someone submits any changes to relevant files.
I was new to the hook concept, but I didn't expect to run in any strange errors when generating the javadoc.
java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc
at com.sun.tools.javadoc.AnnotationDescImpl.annotationType(AnnotationDescImpl.java:46)
at com.sun.tools.doclets.internal.toolkit.util.Util.isDeprecated(Util.java:811)
at com.sun.tools.doclets.formats.html.AbstractIndexWriter.printComment(AbstractIndexWriter.java:186)
After a few succesful searches on StackOverFlow I discovered it had something to do with third-party-annotations. (I make use of the Play framework and that uses a number of other libraries)
So I included everything in a script:
#!/bin/sh
CLASSPATH="~/Play/play-1.1.1/;"
javadoc -d ~/svndoc/ -classpath $CLASSPATH -sourcepath ~/svntest/avon/trunk/ScoreDB/app #packages
But this generates the exact same errors. Sometimes there are 10 warnings, but most of the time there are 27 of them.
Could you guys help me out?
Thanks in advance,
Jasper
Your classpath looks wrong. First, there should be no ; in it (in Unix, the separator is :, but it is not needed at the end). Secondly, do you really have the individual class files in this directory? If there are jar files, you need to either list them individually, or put a * there (but pay attention that bash does not expand it, since you would need : instead of spaces between).
I have no idea if this would solve the problem, though.

Java Reflection not working on my system - working for team members

I am working on a team project in Java. One requirement is that we dynamically populate a drop-down menu of all classes that implement a certain interface. New classes can be added after compile time. To accomplish this we are using reflection.
Problem: All of the drop-down menus are blank on my system. I cannot for the life of me figure out why they are not populating. All other 5 team members have it working on their system.
Things I tired that didn't work:
1) Installing most recent eclipse (galileo) because rest team was using it
2) Re-install most recent java release (jdk1.6.0-17 and jre6)
3) Check PATH and JAVA_HOME variables
Any thoughts as to what else I can try or if something I did should have solved it and didn't? It is driving me crazy.
Edit:
I should have been clearer that we are developing in a team. We are using SVN for version control and we are all running the exact same source code. I even tried checking out a fresh copy of the entire tree from SVN, but I had the same issue with reflection on my system while it worked for teammates.
The team created an executable jar and that ran on everyone's system fine except for mine. Everything worked for me except the reflection bit.
You need to debug your application. This means you have to systematically explore possible causes of the problem. Here are some things that come to mind:
Could your GUI be failing rather than reflection? What if you output with System.out.println() rather than your menu?
Is your reflection code throwing an exception, and are you ignoring it?
Is your reflection code actually being called? Toss a println() in there to be sure!
Is the test for the interface suffering from a typo or similar error that's causing it to fail? Try finding classes that implement Serializable instead!
Is your reflection test running in the main thread and trying to update your GUI? You need to use SwingUtilities.invokeAndWait to get an update to the Swing worker thread.
You're working with Eclipse; Eclipse has a fantastic debugger. Set a breakpoint near where your main action is and then single step through the code.
PATH and JAVA_HOME won't help. PATH only affects dynamically-linked libraries ("native code"). JAVA_HOME is a scripting variable that happens to be used by some Java-based utilities like Ant and Tomcat; it means nothing to the Java runtime itself.
You need to be investigating the classpath, which should be specified by the -classpath option to the java command, in the Build Path in your Eclipse project properties, or in the Class-Path attribute of the main section of a JAR file if you're launching java with the -jar option.
From within your code, you should be able to list the contents of your classpath by examining the system property, "java.class.path"
System.out.println(System.getProperty("java.class.path"));
Problem solution:
Classpath leading to source code must have no spaces in it.
I am running windows XP and, for whatever reason, if the classpath that leads to the jar file or source code that is using reflection has any spaces in it, then the reflection fails.
I took the jar file that works for the rest of my team and ran it from C:\ on my system and the reflection worked perfectly fine.
I do not know why this is so please comment if you know what is happening.
Might be a long shot, but look for differences in security settings for you and your team mates. Article describing more details http://www.ibm.com/developerworks/library/j-dyn0603/ heading "Security and reflection"

How to get MigLayout to work with my project?

I'm trying to make a small GUI app and I want to use MigLayout with it.
As Java newbie I don't know how to get MigLayout to work with my code and I'm running out of ideas.
My project source code is in ~/git/project/src/qdb/
The qdb is my java package name. I downloaded miglayout-3.7-swing.jar and miglayout-3.7.jar and placed them to my project sources and tried to compile the code but I get errors pointing to "new MigLayout()" stating "cannot find symbol".
I was in src dir and used "javac qdb/*.java" to compile (* gets expanded).
I also tried to point classpath to my sources like: "javac -classpath /home/user/git/project/src/qdb/ qdb/*.java" but I still get the error.
Then I've also tried to put the jar files to ~/jars/ and use that as classpath but still the same error follows.
So, how to get MigLayout working?
Simply add the miglayout-3.7-swing.jar to your classpath:
javac -classpath /your/path/to/miglayout-3.7-swing.jar qdb/*.java
(as illustrating in this thread Installing Mig Layout)
If you can compile them (with the above line),
but can not execute the resulting program, you also need to add to the java classpath the library
java -classpath /your/path/to/miglayout-3.7-swing.jar:/your/project/compiledClass/dir qdb.yourMainClass
If you are going to put it into a .jar file, you'll need to specify the Class-Path in the manifest file:
Class-Path: /your/path/to/miglayout.jar
VonC's answer is right. I just want to add (since you are a Java newbie) that you should consider developing using an IDE. They'll save you hours of by-hand-compiling, and will help you integrate your code with libraries (such as MigLayout) more easily.
There are two free IDEs I really like:
IBM's Eclipse.
SUN's (soon to be IBM's) Netbeans.
Also consider this SO thread. And this one too.
Good luck.

Categories