Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
student:eclipse:help [2021/09/05 11:38] bernstdhstudent:eclipse:help [2024/03/25 17:24] (current) bernstdh
Line 55: Line 55:
  
 Unless you are specifically told to do so, **do not** create a %%module-info.java%% file (i.e. **do not** create a module). Unless you are specifically told to do so, **do not** create a %%module-info.java%% file (i.e. **do not** create a module).
 +
 +Also, unless you are specifically told otherwise, select the option to create separate %%src%% and %%bin%% directories/folders  (i.e. **do not** put everything in one directory/folder).
 +
  
 If you are using Checkstyle, you must activate it for the newly created project. To do so: If you are using Checkstyle, you must activate it for the newly created project. To do so:
Line 64: Line 67:
  
 Eclipse projects can be exported as ''%%.zip%%'' files.  To import such a project, click on <key>File</key>+<key>Import</key>, expand "General", select "Existing Projects into Workspace", and click <key>Next</key>. Then, choose "Select archive file", browse to the appropriate archive file, select the relevant project(s) if necessary, and click <key>Finish</key>. Eclipse projects can be exported as ''%%.zip%%'' files.  To import such a project, click on <key>File</key>+<key>Import</key>, expand "General", select "Existing Projects into Workspace", and click <key>Next</key>. Then, choose "Select archive file", browse to the appropriate archive file, select the relevant project(s) if necessary, and click <key>Finish</key>.
 +
 +
 +=== Converting a Generic Project to a Java Project ===
 +
 +Eclipse has many different kinds of projects. Java projects have a "J" above the folder icon in the package explorer while generic projects do not. After backing everything up outside of Eclipse, you may be able to convert a generic project to a Java project by:
 +
 +  - Right-clicking on the project icon in the package explorer.
 +  - Pulling down to "Properties".
 +  - Selecting "Project Natures".
 +  - Clicking on <key>Add</key>.
 +  - Select "Java".
 +
  
 === Customizing the Formatter === === Customizing the Formatter ===
Line 96: Line 111:
 === Creating Packages === === Creating Packages ===
  
-Some courses require that code within a package be organized in packages and some do not. To create a package:+Some courses require that code within a project be organized in packages and some do not. To create a package:
  
   - Right-click on the appropriate project (in the package explorer).   - Right-click on the appropriate project (in the package explorer).
Line 104: Line 119:
   - Unless you are explicitly told to do so, **do not** check the "Create package-info.java" box.   - Unless you are explicitly told to do so, **do not** check the "Create package-info.java" box.
  
 +Subpackages can be created by including a dot/period in the name. So, for example, if you have a %%data%% package you can create a subpackage named %%data.io%% simply by including the dot/period in the name when you create it. However, note that Eclipse will not visually put the %%io%% package insides of the %%data%% package (though it will put the corresponding %%io%% directory/folder inside of the %%data%% directory/folder). This is to remind you that the statement %%import data.*%% does not import the subpackage %%data.io%%.
  
 === Creating Files === === Creating Files ===
Line 117: Line 133:
   - Pull down to <key>New</key>.   - Pull down to <key>New</key>.
   - Pull over to <key>Class</key>.   - Pull over to <key>Class</key>.
-  - Enter the name of the package in the "Package" field (or leave it blank if the class is in the default package).+  - Enter the full name of the package (including any subpackages, delimited with a .) in the "Package" field (or leave it blank if the class is in the default package).
   - Enter the name of the class in the "Name" field.   - Enter the name of the class in the "Name" field.
   - Optionally, complete the other fields and make the appropriate selections.   - Optionally, complete the other fields and make the appropriate selections.
Line 153: Line 169:
 To instruct Eclipse to use them when compiling and executing you should: To instruct Eclipse to use them when compiling and executing you should:
  
-  - Create a directory/folder for the ''%%.class%%'' files or ''%%.jar%%'' file external to the workbench (e.g., ''%%existingcomponents%%'').+  - Create a directory/folder for the ''%%.class%%'' files or ''%%.jar%%'' file external to the workbench/eclipse-workspace (e.g., ''%%downloads%%'').
   - Copy or download the ''%%.class%%'' files or ''%%.jar%%''  file to that directory/folder.   - Copy or download the ''%%.class%%'' files or ''%%.jar%%''  file to that directory/folder.
   - Open Eclipse.   - Open Eclipse.
Line 164: Line 180:
     * <key>Add External Class Folder...</key>     * <key>Add External Class Folder...</key>
     * <key>Add External JARs...</key>     * <key>Add External JARs...</key>
-  - Navigate to the appropriate location and select the appropriate file. +  - Navigate to the appropriate location (which will be the directory/folder containing the ''%%.class%%'' in the first case, and the ''%%.jar%%'' file itself in the second case) and click <key>Open</key> or <key>OK</key> or the equivalent
-  - Complete the rest of the process.+  - Click on <key>Apply and Close</key> (and whatever else you might need to click on to complete the process).
   - You may need to close and re-open the project for the files to be found.   - You may need to close and re-open the project for the files to be found.
  
 Remember, if you only have the byte code, you will not be able to edit these "third party" classes, but you will be able to use them in your source code. Remember, if you only have the byte code, you will not be able to edit these "third party" classes, but you will be able to use them in your source code.
 +
 +== Troubleshooting ==
 +If in trying to run your project you get a ''%%java.lang.UnsupportedClassVersionError%%'', it's likely that you are using the wrong version of Java (usually one too old). Check the expected java version in your course's documents. If you're not sure where to look, it's highly likely that your instructor requires you have at least the same [[student:computer_labs:start|version as the computer labs]].
  
  
Line 218: Line 237:
  
 To find a matching curly bracket (either opening or closing) type <key>Ctrl</key>+<key>Shift</key>+<key>P</key>. To find a matching curly bracket (either opening or closing) type <key>Ctrl</key>+<key>Shift</key>+<key>P</key>.
 +
 +
 +==== Counting Lines of Code (LOC) ====
 +
 +Though there are several software metrics plug-ins available, there is an easy "hack" for counting lines of code.
 +
 +  - Click on <key>Search</key>+<key>File</key>
 +  - Enter ''\n'' (to count all lines) or ''\n[\s]*'' (to count non-blank lines) in the "Containing text:" field
 +  - Check the "Regular expressions" checkbox
 +  - Enter ''*.java'' (or other file type) in the "File name patterns" field
 +  - Select the appropriate scope
 +  - Click on <key>Search</key>
 +
 +The top line of the "Search" panel will show the total number of matches (i.e., lines). You can also get matches/counts by package, file, etc.
 +
  
  
Line 262: Line 296:
  
  
-In Eclipse, applications are started using the <key>Run</key> button or the "Run" menu.+In Eclipse, applications are started using the <key>Run</key> button or the "Run" menu. They are configured from the 'Run" menu using the "Run Configurations..." option.
  
 +
 +=== Run Configurations ===
 +
 +There are different kinds of run configurations, the two most important are configurations for Java Applications and configurations for JUnit tests.
 +
 +To create a run configuration, select the appropriate type and click on the [New launch configuration] button (that looks like a blank sheet with a + in the upper-right corner). Then, fill in the name and other relevant information. For Java Applications, the most important information is entered on the "Main" tab. For JUnit tests, the most important information is entered on the "Test" tab.
  
  
Line 326: Line 366:
  
 You can control what is shown in the Variables View by clicking on <key>⋮</key>+<key>Java</key> and then selecting the items you are interested in. One particularly useful item is "Show References". You can control what is shown in the Variables View by clicking on <key>⋮</key>+<key>Java</key> and then selecting the items you are interested in. One particularly useful item is "Show References".
 +
 +=== Debugging with Third-Party Classes ===
 +
 +Sometimes you will only have %%.class%% files (or a %%.jar%% file) for some of the classes that you are using. When this happens, you won't be able to step into those classes (because you don't have the source code). However, you can still use the debugger. For example, you can step over any calls to methods that you don't have the source code for.
 +
 +Frequently in these kinds of situations, what you want to do is run to a breakpoint and the resume execution until that breakpoint (or another one) is encountered. This can be accomplished using the {{eclipse_resume.png}} button in the Debug Perspective. In other words:
 +
 +  - Set a breakpoint (or multiple breakpoints).
 +  - Step through your code as far as you can (i.e., until you encounter method calls that you don't have the source code for) or as far as is necessary.
 +  - Click on the resume button. This will resume the execution of the code until a breakpoint is encountered.