Eclipse - How To Remove Packages - java

I just started taking this Distributed Systems class, and my teacher says the following on our class website:
Please do NOT use packages! If your configuration of Eclipse uses them
by default, please remove them before writing code!
What the heck is she talking about? I thought eclipse NEEDS to create packages for your project source files to stay organized. How do I remove them?

Packages are not mandatory. If you create a new project in Eclipse, you can directly add your classes to src folder. These files will be under /workspace/project_name/src/ folder. If you add a package, your class files will be placed under /workspace/project_name/src/package_name folder. Your instructor will need to know package names to be able to compile your files and she is probably using a script or something to automatically compile them and that script assumes your files are placed under src folder.

Just remove the first line of your code if exist that says:
package <package-name>;
And if you are creating a new class, then don't give any package name.

Related

Can't make a folder in Eclipse

All I want is to make a folder at the "root" of my eclipse stuff so I can store projects from different classes together. However, it won't let me do that, the "Finish" button is greyed out until I select a parent folder - I must choose from one of the many projects I want IN this new folder. What do I do?
It kind of sounds like you'd be best served by a single project that contains all of the source files from your classes. The workspace is the root directory and any subdirectories are expected to be individual projects.
I agree with what everyone has been saying, create a project for the entire class as 1 project. Then you can create as many classes as needed with main() and only export that single class (or dependent classes as needed) to turn in. In addition, you could package each individual project assignment in a separate package. As stated above, leave your root (workspace) where it is.
Instead of creating multiple projects you may use Java packages option. Create a new package and put all your additional classes over there. Please note that all Java files should be under src/ directory of the eclipse project.

Adding a class to an exisiting Jar files - Eclipse

I think this is a super easy question, but im new to this and not sure what to do. So I have added an external jar file into one of my projects, and was able to decompile the classes using JAD to see some of the class files, the thing is I want to add a new class to one of the directories in same JAR file, compile it and update the jar file. I was googling and I came up with things like an 'ANT build file' but not sure how that would work?
Thanks!
First of all i would check out if the developper of that JAR has provided the source to the classes. This reduces the possibility of JAD not beeing able to fully decompile all the class information.
However once you have all the .java files (including your changed or added class) you can let eclipse build the jar file as follows:
1.) Compile the .java files (Project -> clean..)
2.) File -> Export -> Java -> Jar file (click next)
3.) Select anything that belongs to the jar, input a name and click finish (Note the checkbox that says to export generated class files and resources).
Regarding Ant/ Maven and stuff: Those are just tools that help you. The same result you can archive by opening a console and use javac.exe to compile you can use ant or maven to compile your classes. Its just a matter of configuration.
I recomend you skip Ant right here and directly do the Maven in 5 Minutes tutorial :)
Your approach works. But you can have two classes with same name and package. This will remove the necessarily of updating the jar file.
You must set the loading order to make sure that your new modified version will be used instead of the one which is in the jar file.
Possible to use two java classes with same name and same package?
Before any tweak and class loader, test this approach, may be the default class loader behavior will do what you want.

adding class files to java package in eclipse

I have three .class files that I'm supposed to black-box test. They are under a package named one.two.three. I'm having difficulty accessing them. I started a new java project in eclipse and created a package with the same name. I then proceeded to add the three .class files to bin/one/two/three. If I try using the classes Eclipse can't find them and I get compiler errors. I'm using the appropriate package header. Any help is greatly appreciated, thanks.
assuming bin/ is your output folder in the Eclipse project settings. Simply dropping the class files under bin/one/two/three will not work as eclipse will either delete them (on clean build) or just ignore these extra artifacts. Do as #Ray Tayek says- keep them in a different directory and edit project classpath and add this as class folder. This should work.

Unable to use existing Java packages in Eclipse?

I'm learning Java from Bruce Eckel's Thinking in Java. After reading about packages early through the book, I thought I had got it, but when I decided to use the supplementary code(in the form of a single ZIP), I'm not so sure anymore.
The ZIP file contains packages in the correct hierarchy. I've an extracted copy of the ZIP too. Let's call this folder TIJ4. Both the ZIP and the folder are located on my Desktop. I'm working with an example Shapes.java which has an import statement like this:
import polymorphism.shape.*;. I imported this folder in the Project Properties>Libraries>Add external class folder. The strange thing is that Eclipse does not show an error on the import line, yet it cannot resolve names to types. I could manually create a package, then a class from within Eclipse, but isn't there an easier way to do this?
I've gooogled about this but nobody seems to have the exact problem as me. Here's what I've got so far:
1)New Java Project created. Created a class file Shapes.java in the project:
2) Project Properties>Libraries>Add External Class Folder. Selected my folder TIJ4. Notice that the error on the import is now gone. Apparently Eclipse has found the polymorphism package.
3)But I still get XXX cannot be resolved to a type errors all over the place!
what do I do? I also tried Project>Build Path>Add external archives and selected the ZIP, however, ended up in the same place.
As the Zip file contains only Java sources, you will have to compile them. Simple way, right now, is extract them into the src directory in your eclipse project. That way they will be compiled and automatically included in the classpath.
The reason for not able to resolve the classes even the import error goes away, is the zip file contains the directories that satisfy the package structure but there are no compiled classes (the .class files) are found in them.

How do you add a directory of java classes to a project?

I have a Java project I'm working on, and wish to include a directory full of classes. These are the "JEdit Syntax" classes, and come within two packages:
org.syntax.jedit
org.syntax.jedit.tokenmarker
However, everywhere I look it tells me to "import the entire jar file". My problem is that there is no jar file, just a directory with a subdirectory, both filled with *.java files, each containing a class.
In Netbeans 6.5 I added a library by "Jar/Folder", and both appear in my new library I created, but when I go to import the two packages listed above, I get the error that "org.syntax.jedit does not exist (cannot find symbol)".
Can anyone show me what I'm doing wrong?
Thanks a ton.
It sounds like you have tried to add the two packages to your classpath seperately - and at the wrong level.
If you are pointing at a folder, you have to point to the "root" folder of the package hierarchy - ie in this case the folder which is the parent of "org"
Then from there it will look down the package/folder hierarchy org/syntax/jedit to find your classes.
So if your files are in the directory "c:\mylib\src\main\java\org\syntax\jedit" then you need to point the compiler folder at "c:\mylib\src\main\java".
That should then find all the classes.
I agree with evnafets, you probably added the org directories, but you should have added the directory that contains them. You can also build a jar out of those directories easily if there is an ant file (build.xml).

Categories

Resources