I'm trying to attach sources for this library called FileDrop so I can view documentation. When I click Attach Sources... and select the directory with the source code, nothing changes. It still has the Sources not found message at the top of the class. However, in my external libraries section, if I manually expand the library jar file, I can view the original source in there. I think this is because the library jar has the full, uncompressed source in it.
The zip file of the library has this structure after downloading and extracting it:
filedrop-1.1
Example.java
filedrop.jar
FileDrop.java
So the source files do not have any package...not sure if that is part of the problem. The two .java files are also in the jar file. So when I create a library in IDEA, the jar shows up in External Libraries under the library I created, but the source does not.
In the Project Structure -> Libraries screen, it shows the jar file under Classes, and it shows the parent directory (filedrop-1.1) under both Classes and Sources, but it is apparently not detecting any sources within them. This is the screen where I've been trying to add the sources, and they show up here as expected, but apparently no sources are found.
This is IntelliJ IDEA 13.1.4.
The packaging of this library is extremely weird. The jar file contains two different FileDrop classes, one in the default package and another in the net.iharder.dnd package, which seems to be a newer version. It also contains two source files (Example.java and FileDrop.java), the second of which seems to be the source code of the old version of the class (the one in the default package).
The CVS repository at http://iharder.cvs.sourceforge.net/viewvc/iharder/filedrop/net/iharder/dnd/ seems to contain the new version of the code, so you can do a CVS checkout and attach the iharder/filedrop directory from the checkout as sources to the library.
Related
I've currently finished my project, but can't get it to work when it is exported. I use JAXB to read and write XML Files and also have dependencies on other external Folders, which are needed to use a POS-Printer.
I've managed to link my external XML Save-Files with absolute paths, but not with relative paths. So that worked, although not the way i wanted. Yet, using the external class folder for the printer didn't work at all.
This means, that in my Eclipse Project Build Path i've added a class folder, which contains all of these needed files (which are not only jars, so adding them one by one wouldnt work). So exporting my project to a jar either includes all the files into the jar itself, or doesnt include them at all.
Everything works perfectly in Eclipse, but not when i export it.
My folder structure looks like this:
src
/model
/view
/control
data
/articles.xml
/...
JavaPOS <--- needed folder with all its files
/jpos.xml
/xerxers.jar
/swt-..-.dll
I've tried:
InputStreams is = getClass().getResourceAsStream(url);
absolute paths
manipulating the manifest file and/or jar structure
runnable and non runnable jars with nearly every combination of options
putting the files inside the library "by hand"
changing the build path of the project
My Question is:
How do i get my jar-file to know where these files are?
EDIT:
Do you think Maven or an Ant file could solve my problems? I don't have any experience with those.
The Problem was, that i had more than one JRE installed and that the one eclipse was using, had all the dll files, but the other ones didnt have it. So i had to add them manually, because reinstalling the drivers of the printer didnt change anything. Gotta fix that somehow, but right now it works and that is all i wanted.
Turns out i didn't even need that Folder, just needed one file out of it and the missing dlls.
I have downloaded some source code that contains src folders with some .java files. I want to try to run the code in netbeans.
This is the structure of the folder :
C4.5/src/main/java/myc45/
and in these folder include some .java files.
What should I do first?
When you create a project in Netbeans, one of the options in the project creation window is create project from existing source. If you have an existing project, you can also edit the project properties and tell it what the source folders are.
As an alternative to #PaulJAbernathy 's solution:
create a new project in Netbeans
via the projects windows, create a package myc45 (the package name used in the code you want to import) - you can do so by rightclicking, new Package
now, inside the src directory of your project directory you'll find a directory called myc45. Drop the source files into that directory using whatever file browser you commonly use. You'll see that Netbeans picks up the files almost immediately in the project explorer.
you can now use the code.
A bit messy, but there are advantages: if eg you want to transform a bunch of existing code files into a Maven type project, this is probably the easiest way.
There doesn't seem to be any code there. I expected to see class declarations so I could see what the code does but instead there's some
Are they somehow precompiled? What's the difference between included Jar file and a pure code?
You are looking at .class file, which is a generated when you compile .java file. To see what the program does, you have to look into .java file. You can refer official java documentation for that.
A .jar file is packaged file with .jar extension, it contains compiled java files and their class files. This file is usually imported into projects to use the classes defined in that package.
You can use "jar xf jar-file" command in command-prompt/terminal to extract the files from jar and look into the package.
A JAR will normally contain compiled class files. It may also contain source files or there may be a separate JAR that contains the source files, but not necessarily so.
If you want to use the library in your project, then a JAR of compiled class files is what you want. If you want the source code, then you'll have to see if it is available from wherever you downloaded this from. If all you want is to see how to use the classes, then probably what you want are JavaDocs for the library you are using. This is an HTML based API documentation.
Well, this is because you haven't attached any source for the mentioned dnsns.jar. You can attach source to existing JAR files in Eclipse. Refer this SO post: Is there an easy way to attach source in Eclipse?
For this specific dnsns.jar, it is part of your JRE, and if you are not able to see its source in your IDE, then it means that the Java that you have setup in IDE lacks the source. If your installation does not have the source (src.zip), then you can get it manually as mentioned on this SO post: Where to find Java JDK Source Code?
EDIT: Alternatively, you can also use a decompiler (e.g. http://jd.benow.ca/) to reverse engineer the source from byte code, though, it may not be the exact match to the original source but you can understand the overall idea. You can add the decompiler as the default program for opening .class files in eclipse Windows > Preferences > General > Editors > File Associations. Select *.class filter and add your decompiler as the program. Though, it is not as clean as attaching the source to JAR, but may work if you don't have access to source.
EDIT2: About your question
What's the difference between included Jar file and a pure code
Eclipse can find .java files for your own code because obviously they are in your workspace. But when you add a JAR file as library, it may have the source (.java) in it or not. If the source is available, eclipse can display it by default. If not, you have to add it manually.
I have a Java JAR file that was developed to run in the browser. It works fine. There doesn't appear to be any sort of build file associated with the source code I've been given and I'm attempting to create a project and/or build script.
The source code references some third party code. What I've done is unzipped the JAR file into a folder that has this structure:
\App\src\com
\App\src\META-INF
\App\src\applet
The "com" folder contains subfolders which contain the .CLASS files for the third party libraries. "applet" contains the .JAVA source code files (one folder, maybe 15 files).
The code appears to be written in 1.4 syntax (I manually attempted to compile some of the .JAVA files and it complained that some things were deprecated and/or required the older version).
I created a Java Project in Eclipse and pointed it to the \App folder. Then I went into the Properties for the project and went to Libraries and and clicked on "Add Class Folder" and added the \App\src\com folder. Then I went to "Order and Export" and moved this to the top. I also set the Java Compiler version to 1.4.
I am getting a large number of compiler errors, all of which seem to stem from the fact that it says it can't resolve an import. This import is the set of .CLASS files contained in the "com" subfolders. The namespace matches the directory structure.
This seems like it should be really straightforward, but I've tried various things and don't seem to be making any progress. Based on what I've read I'm sure it has something to do with the pathing but I'm at a loss at this point on how to fix it.
(I'm sure it goes without saying that I'm not a Java dev.)
Any thoughts or ideas as to where I'm going wrong?
Can you please try to right click on Eclipse's Navigator. Select Import>General>archive file> (Jar file that you want to import).
You should be getting the jar file correctly imported at this point. Do tell me if you face any problems.
I downloaded an API but there is no jar file in it. It has the packages(folders) and the source code. I tried adding this in various ways in Eclipse but still I don't get the "import ...." when I press F2 on the underlined red classname. I have added projects and Jars in Eclipse all the time and it has worked. Since this is the source code should I take any extra steps in order to make it work?
Regards!
If the source is available to you (.java files) you must create a new source folder, then copy the source tree (root package e.g. the folder com or org) into the new source folder just by using a standard file explorer and copy&paste:
Edit: You could add the source files to your existing source folder as well, but I'd avoid that. Best solution would be to create a separate Java project containing just the source files of the external library. You also need proper code management, so that you do not accidentially make changes to the external source files!
You may create jar from the classes you have received in API packaging and place that jar into the classpath of the project
Enjoy !!!