Importing .java files on to a Java Project in eclipse - java

I'm working on a Java project in Eclipse that outputs a bunch of text/numbers on to an excel file. I am using a bunch of quickTapSurvey .java files for the project. QuickTapSurvey is just a survey app where users can add/modify the questions according to their needs. I imported the .java files by right clicking on the "default package" and then clicking on the "File system" category. Now that I have all the .java files in my project, they have red "X" marks next to their names, which I am assuming denotes an error (look at the attached snapshots). The code itself has red underlines everywhere. Can someone please tell me what I am doing wrong.
List of imported .java files. note the x marks:
Imported files at the top of the main program:

Your java files reference classes that Eclipse does not know about (they are not found in the classpath). These missing classes are probably related to quickTapSurvey; read their documentation to see how to fix this.

Related

Where does eclipse keep the information about the sources

Yesterday I've imported some Java files within my Java project (just for being able to compile them into *.class files), I have then removed those files and now my Eclipse is constantly showing the following complaints:
Could not move: <the mentioned Java file>
File not found: <again the mentioned Java file>
In top of that Eclipse mentions this issue being present in the plugin "org.eclipse.core.filesystem".
Now I'd like to do the following:
I'd like to go to the file which contains this obsolete reference and delete it in that file. (In Visual Studio this is a piece of cake)
How can I do this in Eclipse? Where does Eclipse store its project file(s)?
Put the mouse cursor on the class or method name in source code and hit
Ctrl+Shift+G.

Netbeans automatically cloning my jar based packages with their empty 'name equivalents'

I'm new at java programming so i just wanted to try something with ssh understand how it works and so i downloaded a java library which is mentioned in this Stack Overflow answer
. After a lot of failed attempts on importing this library into netbeans. I decided to simply put the files into my src folder. But Netbeans ide duplicating packages in the jar file with their 'name equivalent' empty packages and this prevents me to reach the classes in the packages because the IDE and the Code completion automatically sees the empty packs.I've search the network couldn't find anything about this problem.I 'm ready to share any log files if there are any of them .Here is my screenshot about this situation.
Screenshot Attachment
OS : Linux Mint Rosa
IDE : Netbeans 8.1 Linux version
Edit : I Already looked these topics
How to use .jar files in NetBeans? : At first i've tried this and in this solution netbeans not duplicating any empty packs but when i start to type somethin' like that import sshj.foo.*; Auto Complete can't find anything and also if i try to write the whole path to a specific class which is in an specific pack IDE gave me an error the pack that you're looking for is not exist.Secondly I've tried this
and got the same issue at first try.I can see the packs,classes and other stuff but still can't reach them in a random class which is imported project.
How can I include external jar on my Netbeans project : I've tried this and also this ran perfectly without errors as they said but when i try to reach classes still got the same problem so nothing changed.
How to add a JAR in NetBeans :
In this topic all of the replies explained types of libraries.That's not even related to my problem
How to use classes from .jar files? : I've tried to do explained in this reply also and I've transfered my jar file into a compiled .class extension file and this didn't solve my issue too.
I've just solved that problem with downloading part of the libraries from here.
All libraries need to contain three kind of jars ;
1 . Compiled files containing jar (with extension .class)
2 . Source files containing jar (with extension .java)
3 . Javadoc files containing jar (optional)
Open a project find libraries folder on ide right click and choose Add JAR/Folder specify the directory that contains the compiled files.After importing library hit right click over it and choose edit then specify the source files and javadoc files directories you are ready to roll.

Having trouble compiling and recreating a JAR file using Eclipse

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.

Use project's own .java files as resource files

I have made a small program in Java that displays its .java source with a gui. It does not use FileChooser to do this. I am reading the .java sources with the aid of following statements
String resName = "/dev/classes/"+name+".java"
Scanner s = new Scanner(FilePrinter.class.getResourceAsStream(resName));
where name is the name of the .java file i.e. if the file is MyProg.java then name==Myprog. Of course my program is inside the dev.classes package
The thing is that when I export my project to JAR and include source files this works because source files reside inside the /dev/classes/ directory.
However, I haven't yet discovered a way to make my program run in Eclipse or from the command line without giving me exception.
And of course when someone tries to add those source files to be used automatically as resource files the process fails.
Can I somehow use the same code both when running from Eclipse and from the JAR? It must be something very trivial but because I am not Java expert I cannot see.
I found how to do it. Actually you either have to use Ant or Maven. However, this can be done in Eclipse as well as follows:
On the Eclipse Project Properties>Java Build Path you can choose on the bottom Default Output folder: <your_project_name>/src.
This causes class files be compiled in the same directory as the .java files and finally does what I wanted.
Thanks to #AndrewThompson for suggesting to try this

How do I use manifest.mf to contain correct location of the main class?

Can anyone help me with this? I have not been able to find anything that answers this for exactly what I need. All the answers I find have to do with adding additional libraries to manifest files and what not.
Here's the situation:
I have written a game using NetBeans 6.9. The game is in Java. There are about 80 classes. All classes are contained in the default package. The game executes correctly. I've been working on this project for about 18 months and I always maintain executable code as I have developed the game.
What I did:
I needed to import something from a static class I'd written, into another class I was working on. In order to do that, I had to move everything out of the default package. I used NetBeans to refactor everything into a custom package.
What happened:
When I do a "clean and build", the project builds successfully.
When I do a "run main project", I get the following error:
java.lang.NoClassDefFoundError: WarMachine
Caused by: java.lang.ClassNotFoundException: WarMachine
...stack trace
Could not find the main class: WarMachine. Program will exit.
I have checked the .jar file and I see that all the compiled .class files are there, including the main class (called WarMachine.class). All the .class files are in a directory called Machine (that was the package name I had NetBeans refactor everything into).
From what I have been able to find on the internet, the problem is that my manifest.mf file does not point to the correct location of the WarMachine.class file.
What does my manifest file need to say? I don't use any other libraries or anything like that. I have 78 classes, all of which are in the "Machine" package. Can anyone help me?
Thanks for your time!
You have to tell Netbeans where the main class file is. Right click on your project, select "Properties", then go to the "Run" tree element on the left.
You will now have a "Main Class" textbox on the right. Click "Browse" and select your main class. Netbeans should then fix the manifest file for you.
In case you are curious, your manifest file inside the .jar file of the dist folder should have a line like this:
Main-Class: Machine.WarMachine
As an aside, it is considered standard practice to use lowercase letters for package names. You should call your package machine.

Categories