ImageJ: Debug with bioformats - eclipse

I have downloaded imageJ source and imported into Eclipse. At the moment, I'm working on a plugin for imageJ and I can run imageJ with my plugin from eclipse and debug if I want. My problem is that I wish to init imageJ from eclipse but with the bioformats reader plugin loaded so I could open .lif files. How can I introduce this plugin into the imageJ source code? I have tried to add dependecies to the .jar file of bioformats in my project but it doesn't work.

Do not copy around source files, nor JAR files. You should manage your project dependencies using Maven or similar 21st century build tool (Gradle is also effective). Add a dependency on net.imagej:ij and ome:formats-gpl and maybe other Bio-Formats artifacts, as you need.
See also:
The Development page of the ImageJ wiki.
The minimal-ij1-plugin example

Just for who ever is looking at the same problem:
Download all the source code: https://github.com/openmicroscopy/bioformats
Copy the folder: bioformats-develop\components\bio-formats-plugins\src to your project.
Copy loci.plugins.LociImporter.java to ij.plugin.
Delete loci.plugins.LociImporter.java
Modify ij.plugin.LociImporter.java and add the line of arg:
public void run(String arg) {
DebugTools.enableLogging("INFO");
arg = "location=[Local machine] windowless=false "; //<-This one
[...]
}
Modify loci.plugins.in.Importer.java:
//import loci.plugins.LociImporter;//substitute this import per
import ij.plugin.LociImporter;//this one
Modify ij.Menus.java:
[...]
Menu importMenu = getMenu("File>Import", true);
addPlugInItem(importMenu, "Bio-Formats", "ij.plugin.LociImporter",0,false); //<-Add this line
[...]
Add bioformats.jar as an external lib to the project.
Run the project. Now you can open .lif from file->import->Bio-Formats. With this modification you won't be able to do drag and drop but you will be able to use this plugin just opening files with this menu. As this is only using the "import" this is only useful for opening. If you want something about saving, you should call loci.plugins.LociExporter("") in the same way I did for the import. (actually with my modification we are calling ij.plugin.LociImporter("location=[Local machine] windowless=false ")

Related

Adding source code to all jars of Tomcat9 Targeted Runtime in Eclipse so that F3 opens source code

In a Dynamic Web Project in Eclipse I have a Tomcat9 attached as a Targeted Runtime (I downloaded binary distribution from official site
But if I press F3 on any class (say, SimpleTagSupport class) no source code appears because it is not attached.
How to add source code?
I understand I can download source code distribution
And I understand how to add source code:
In my case ( SimpleTagSupport ) it is
But can I somehow attach source code to all jars in Tomcat Targeted Runtime? It is a tiresom work to manually find source and attach it to each jar!
Besides I cannot find needed source-folders for all respective jars, b/c source distributions looks like this:
Also it turns out ot be that java/javax/servlet/jsp/tagext folder does not contain any valid source files, but what shall add as source to servlet-api.jar or for javax.servlet.jsp.tagext package (for SimpleTagSupport class)...
The idea is that for every .jar (for example for servlet-api.jar) you specify entire src.zip file (Eclipse will figure out the needed part itself)
Solution is found here
Use: https://javaee.github.io/javaee-spec/javadocs/
If we add source files then besides opening source by F3 it also enables tooltip (javadoc) help (taken from javadocs inside source files) on hover (or F2), but Shift+F2 would not work.
To enable Shift+F2 we need to explicitly attach Javadoc (attach source is not enough for Shift+F2).
Download Tomcat's Full Documentation (not source!!!), unarchive it and then use file:/// notation:
file:/K:/SERVERS/apache-tomcat-9.0.16-fulldocs/tomcat-9.0-doc/servletapi
Now Shift+F2 is enabled!

Import .java Files Into the Correct Package

I have a bunch of *.java source files that contain classes in various packages. I am trying to import all of these files into Eclipse projects, but Eclipse always places them in the default package.
How can I tell Eclipse to place each of the files in the appropriate package subdirectory, so I don't have to create all the various packages manually?
I have tried the import from file system feature as well as copying the files into the project, all of which would place the files in the default package rather than those ecplicitly stated in the package statement on top of each file.
Related SO questions only deal with referencing packages outside of the project's src directory hierarchy, manually creating files in the suitable package directory, missing import statements, or bulk-renaming packages, but it doesn't seem like this problem has already been discussed.
Update: As requested in the comments, here are some example files:
Test1.java
package some.random.pkg;
public class Test1 {
}
Test2.java
package some.other.pkg;
public class Test2 {
}
Test3.java
package yet.another.pkg;
public class Test3 {
}
Place all of them in the same directory, then try to import them into a Java project in Eclipse without manually creating the directories for the various packages.
Update 2: In order to clarify the scale, assume that there are actually approximately 100 files like these (of course, with more contents ;-) ) on a weekly basis, which is why I'm looking for an automated solution.
I was somewhat bored, so I created a Java app to get all .java files from it's current working folder and put them in the appropriate subfolders.
You can then copy/paste the newly created folders/files into Eclipse.
Source code and runnable .jar: https://github.com/felipeweber/OrganizeJavaSources
To execute it you will copy/paste the runnable .jar in the folder you have all your .java files in, and run it with java -jar OrganizeJavaSources.jar from a prompt or command line.
It should work in both Linux and Windows (and probably MacOS too).
In my tests it worked perfectly with sane files.
Please note I haven't done any error treatments and so fourth, but feel free to contribute.
Good luck
According to this link you can get what you actually want to do.
File -> New Project/Dynamic Web Project
then
File -> New Folder, click "Advanced" and select "Link to folder in the file system".
After that right click on the folder and select BuildPath -> Use as source folder..
That is it..
OR
you can create a new folder, copy top-most folder containing *.java files and paste it. Then right click on it, select BuildPath -> Use as source folder...
I hope it works for you!!
Well we are programmers here right? so as far I do a research its kinda hard to find this kind of feature in any IDE's because a programmer must be warned that he put a java file in an incorrect package and must not automatically arrange it for the programmer.
Well I suggest you a create a simple java console program that can do the file manipulation for you and I know it would be easy for you. this will be the possible algorithm of the program
Read a .java file
Check the package line until the terminator ; on that .java file
relocate that file according to the package name, well replacing . with directory separators can be used as address where you will relocate the file.
Create the folder if the relocation folder of the file doesn't exist
Do this repeatedly until all files are relocated.
Well me also wants this kind of feature not only in eclipse but also on other IDE's well ill be waiting for further answers in this question.
You need a hack.
I hope you are using linux, otherwise is going to be more difficult :)
1- Create a little java program that reads and executes an .sh file
Here an snippet that shows how you can atemp to read from an script
ProcessBuilder pb = new ProcessBuilder("myshell.sh", "myArg1", "myArg2");
Process p = pb.start();
2- Create the .sh script and make sure java is picking it correctly(Just place some echo message in the script and make sure its being printed)
3- The goal with this hack is to try to use a grep that reads all the files with the .java extension and pipe it to the mv program which will put them in the correct folder.
4- The way you will find out how to put what in which folder(package) will be possible because you can read each of the files using cat and this way determine where they should go. The mkdir command should help you create the folders correctly before moving the files.
5- If you are not sure about this solution, let me just tell you that this is a highly complex task that requires you to examine well and recognize all the patterns. I am confident it is possible and that you can do it using a conditional piping logic and some nice relaxing chill-out music to help you focus.
Here I end you some BASH guide to refresh your mind
Good luck, and happy new 2013
When a file is in the wrong package, Eclipse will offer you to fix the error by moving the file. With the "quick fix" feature (select in the Error view, press CTRL+1), you can easily move them. Try selecting them all at once, maybe your Eclipse version is newer than mine and can fix them all in one go. If not, it is still faster than manually creating the package.
So this is what I did ...
New -> Java Project
(options: click "use project folder as root for sources and class files")
Next
Select "Link additional source" (under Details)
Browse "Linked folder location" and select the top folder (containing all your packages etc.)
Finish
If you already have a Project created then ...
Right-click on project in package explorer and select Properties
Select "Java Build Path"
Select "Link Source" (on the Source tab)
Browse "Linked folder location" and select the top folder (containing all your packages etc.)
Finish
If your files are not in directories corresponding to the packages defined within them, then TAKE A BACKUP OF YOUR FILES (i.e. copy them all to another directory) and try this:
Compile the following program with javac MakePackDirs.java and run using java MakePackDirs and directory and file structures will be created according to package declarations and then use procedure as described above.
import java.util.regex.*;
import java.util.*;
import java.io.*;
public class MakePackDirs {
public static void main(String[] args) throws Exception {
String pkg;
for (File f : new File(".").listFiles(
new FilenameFilter () {
public boolean accept (File dir, String name) {
return name.endsWith(".java");
} })) {
if (f.isDirectory()) continue;
System.out.println("Processing " + f.getName());
Scanner s = new Scanner(f);
try {
Pattern p = Pattern.compile("^[ ]*package +[^;]*",
Pattern.MULTILINE);
if ((pkg = s.findWithinHorizon(p,0))==null) continue;
}
finally {
s.close();
}
System.out.println("Found " + pkg);
pkg = pkg.split(" ")[1];
pkg = pkg.replaceAll("\\.","/").trim();
System.out.println("Creating " + pkg);
File dir = new File(pkg);
boolean created = dir.mkdirs();
if (!created && !dir.exists())
throw new Exception("Can't create package directory");
// Moving file
File dest = new File(dir, f.getName());
boolean renamed = f.renameTo(dest);
if (!renamed)
throw new Exception("Can't move file to " + dest.getPath());
System.out.println(f.getName() + " moved to " + dir.getPath());
}
}
}

How do you configure eclipse to work with a project that wasn't created by it (java)

I have been using the text editor gedit and the terminal for my latest project but I find that I have so many classes it would be more useful to be working with a separate directory for my .class and .java files so I can see what is going on more easily.
Unfortunately I have not been able to figure out how to get eclipse to work with a project that has already been made (or even one that was already made on eclipse with another computer!). This was not such a problem with two or three classes but I am getting to have so many that it is really tedious- It seems to want me to build a completely new project or nothing.
EDIT (additional info):
I don't think it will be possible to show the code of the project as I current have 12 classes for it but by the end I may have one or two more...
I know how to make a project in eclipse. What I am not sure how to do it open a directory full of .java files in eclipse that were created using a text editor rather than in an eclipse project and get eclipse to accept it as a project.
Does anybody know how to achieve this task?
You can import your project into eclipse doing the following steps:
Create a new Java Project in Eclipse (By going to File -> New -> Java Project) select a name for the project and you can select finish
You have to import your existing code to eclipse, go to:
File -> Import -> General -> FileSystem
Then browse to the directory where your code is currently, and say you want to import into the project you created in step 1
Afterwards remember to go to the project properties (right click in the project folder while in the navigator view, for example) and make sure the java build path has the right source folders configured.
Fortunately, you can use eclipse for any project previously created. Do you possibly have the code to show us how you are applying to the project in eclipse?
For example, you can create a project and class, then copy over starting from public static void main(String[] args) {
down to the bottom, then import the important stuff above the main class name.

How to build a downloaded a java source code in net-beans 6.9?

I have downloaded source code from http://e-adventure.svn.sourceforge.net/viewvc/e-adventure/ .
How do I build it and run it in netbeans ?
There is a Compilation.txt file in the source code. You should read that and follow the directions. It says that it is an Eclipse project. Once you have followed the directions (notably downloading a jar file archive), you can try the:
File -> Import Project -> Eclipse Project
menu option and try and import it. Then, perhaps, it will build for you. I have not done this with an Eclipse project, so I don't know how well it works. It may well need some tweaking to get right.

How do I open the GWT samples in eclipse Helios and GWT 2.1.1?

What is the straight-forward way of importing one of the GWT samples in eclipse Helios + GWT 2.1.1. It seems like the content of the zip file doesn't contain any project files for eclipse.
I tried the following:
create a GWT project 'bla'
Delete the src ad war folder and
replace it with the src and war
folder from the sample
refresh the project in eclipse
hit 'run'
[ERROR] Unable to find
'bla/bla.gwt.xml' on
your classpath; could be a typo, or
maybe you forgot to include a
classpath entry for source?
So I go to the run configuration and remove the path for the example projects from the arguments list. I also changed the name of hosted html page to the one in the sample. Hit 'run' and:
[ERROR] Invalid version number "2.0"
passed to external.gwtOnLoad(),
expected "2.1"; your hosted mode
bootstrap file may be out of date;
Now I need an out of date version of GWT to run these samples? What is going on, I just want to look at a sample to learn a new concept.
Reading the readme.txt in the GWT samples directory I came across a solution that works on Eclipse 3.7. Assuming you have ant installed on your machine, execute the following from the sample's directory:
ant eclipse.generate
This will generate both the .classpath and .project files needed to import the sample into Eclipse and run it.
Here the relevant excerpt from README.txt:
-- Option A: Import your project into Eclipse (recommended) --
If you use Eclipse, you can simply import the generated project into
Eclipse. We've tested against Eclipse 3.4 and 3.5. Later versions
will likely also work, earlier versions may not.
If the directory containing this file does not have a .classpath or
.project file, generate them by running 'ant eclipse.generate'
In Eclipse, go to the File menu and choose:
File -> Import... -> Existing Projects into Workspace
Browse to the directory containing this file, select "Mail".
Be sure to uncheck "Copy projects into workspace" if it is checked.
Click Finish. You can now browse the project in Eclipse.
To launch your web app in GWT development mode, go to the Run menu and
choose:
Run -> Open Debug Dialog...
Under Java Application, you should find a launch configuration
named "Mail". Select and click "Debug".
You can now use the built-in debugger to debug your web app in
development mode.
In eclipse 3.7, instead of Run -> Open Debug Dialog..., its Run -> Debug Configurations. I got both the showcase and mail samples running following those commands. Should work for all of the other samples as well.
The examples that come with GWT SDK were built in different ways. Some are Maven builds, others use Ant. Eclipse can handle these common builds directly, but you have to choose the right option.
So, if you want to open the Expenses project in eclipse, you would look in the projects root directory (i.e. ../gwt2.4/samples/Expenses) where you'll find a file called pom.xml. That is a Maven build file. To import it into your Work space select:
File->Import...
Open Maven->Existing Maven Projects, and click on Next > button
Browse your file system til you reach the Expenses folder. Click on it and Select OK.
At this point it will show you the Projects in that directory in the Projects: area of the window...only one in this case: /pom.xml com.google.gwt.sample.expenses:...etc.
click on the checkbox for that project, Next>
Finally, it ask you to map plugins. You'll need to select in the drop down menu under Actions the required plugins (such as m2e).
In other project folders you may find a build.xml file instead. That's an Ant build file. To import that you do something similar, but different (of course!):
File->New->Project...
Open the Java folder and select "Java Project from Existing Ant Buildfile", Next >
Click the Browse button, dig through your directory to the project folder and select the build.xml file, and Open it.
Project name should fill in automatically, just select the declaration to use in the middle window and click Finish.
Since those tutorial only include the src and war directory, the idea remains to:
create a new project following this tutorial
remove any created class part of the example files which are automatically added (see Issue 1547)
Unfortunately the Google Plugin does not allow to created a new Web Application Project without creating template files. The template files are nice for the first try but annoying if you want to start from scratch with a new GWT application.
copy the src and war directory in place within the now empty project
Following your ticket 5847 (No easy and straight-forward way to make examples work in eclipse),
as xo4yhamope comments, you need the right GWT option.
and did you consider the Issue 5038 about the error message:
Unable to find 'xxxx.gwt.xml' on your classpath;
could be a typo, or maybe you forgot to include a classpath entry for source?
This message usually means you attempted to refresh the browser before dev mode has had a chance to finish loading the module.
The uppercase/lowercase confusion happens because the module has been renamed to 'stockwatcher', but dev mode cannot map 'stockwatcher' to "StockWatcher' until it has finished loading the entire module.
So, it's just a matter of waiting a few seconds longer after the Development Mode pane says I should go to http://127.0.0.1:8888/StockWatcher.html?gwt.codesvr=127.0.0.1:9997 ?
That seems a little messed up. It should wait until it's actually ready before telling me it's ok, because users (like me) are going to go there as soon as the UI says it's ready.
The other confusing part is that the server begins serving the host page as soon as that message in the UI comes up. Because this was happening, I assumed that the server was completely up, even though (as it turns out) it wasn't.
Anyway, waiting a few more seconds seems to resolve the "Unable to find 'stockwatcher.gwt.xml' on your classpath" problem. Thanks!
I'm beginning to suspect this is a bug in the samples. I am adding this answer so it can be marked as an answer when I get confirmation about that.
I was trying out some other samples and came across this page. At the top is a little explanation for how to download and import the sample.
Before you begin
The StockWatcher project
This tutorial builds on the GWT
concepts and the StockWatcher
application created in the Build a
Sample GWT Application tutorial.
If you have not completed the Build a
Sample GWT Application tutorial and
are familiar with basic GWT concepts,
you can import the StockWatcher
project as coded to this point.
Download the StockWatcher project.
Unzip the file.
Import the project into Eclipse
From the File menu, select the Import... menu option.
Select the import source General > Existing Projects into
Workspace. Click the Next button.
For the root directory, browse to and select the StockWatcher
directory (from the unzipped file).
Click the Finish button.
If you are using ant, edit the
gwt.sdk property in
StockWatcher/build.xml to point to
where you unzipped GWT.
Now this is what I call straight-forward and easy.
At that point I had already built the StockWatcher in a previous tutorial but I got intrigued by the fact that it was explained exactly as I tried it the first time. So I downloaded the project and it had the correct eclipse project structure. I tried to import it 'et voila' I have the project in eclipse. I runs out of the box (with warnings). That is how expected the samples to be.
This experience leads me into thinking that the sample projects are malformed (as eclipse projects) and need to be updated. Let's hope my issue report leads to results.
-- Option A: Import your project into Eclipse (recommended) --
If you use Eclipse, you can simply import the generated project into Eclipse.
We've tested against Eclipse 3.4 and 3.5. Later versions will likely also
work, earlier versions may not.
If the directory containing this file does not have a .classpath or .project
file, generate them by running 'ant eclipse.generate'
In Eclipse, go to the File menu and choose:
File -> Import... -> Existing Projects into Workspace
Browse to the directory containing this file,
select "Mail".
Be sure to uncheck "Copy projects into workspace" if it is checked.
Click Finish.
You can now browse the project in Eclipse.
Copy from readme.txt supplied by samples. I tried this method, it's OK.
To import GWT showcase(2.5.1) I did following steps:
Create a new Google Web Application Project
New –> Other –> Google –> Web Application Project
Provide the project name “Showcase” and the Package name is com.google.gwt.sample.showcase
Click Finish
Go to eclipse plugin folder and traverse to the gwt
Under that folder go to gwt-2.3.\samples\Showcase
Copy (Ctrl C) all the contents. The contents are
a. src
b. test
c. war
d. build.xml
e. README.txt
In the eclipse, right click on the Showcase project and paste. Overwrite all the files
The files should start copying without any problem
Right click on the Showcase and Run As “Web Application”
You should have your Showcase working like Gem!
For me it worked like a charm ;)
Ref : http://simplestepswebdev.wordpress.com/2011/05/16/import-gwt-samples-into-eclipse/