banner



How To Change Class File In Jar

4.eleven. Using .jar and .class Files

Problem

You lot need to access code in a .jar or .grade file in your projection, but Eclipse tin't find these files.

Solution

Select the project in the Package Explorer, and then select Project Backdrop to open up the Properties dialog. Click the Libraries tab in this dialog, click Add External JARs for .jar files or Add Form Folder for .class files, navigate to the .jar file or to the folder containing .form files, and click OK.

Give-and-take

Frequently y'all need other code in the build path, such as .form or .jar files. For instance, say you're developing a Java servlet, as shown in Instance iv-3.

Example 4-3. A simple servlet

package org.cookbook.ch04;  import java.io.*; import javax.servlet.*; import javax.servlet.http.*;  public class ServletExample extends HttpServlet {      public void doGet(HttpServletRequest request,         HttpServletResponse response)         throws IOException, ServletException     {         response.setContentType("text/html");         PrintWriter out = response.getWriter( );         out.println("<HTML>");         out.println("<Head>");         out.println("<TITLE>");         out.println("Using Servlets");         out.println("</TITLE>");         out.println("</Caput>");         out.println("Using Servlets");         out.println("</BODY>");         out.println("</HTML>");     } }

A lot of the support for servlets is in servlet.jar. Eclipse can't find servlet.jar past itself, so a lot of wavy red lines will announced when it comes to the imports, as shown equally in Figure 4-17.

Missing the servlet.jar file

Figure 4-17. Missing the servlet.jar file

To add servlet.jar to the build path, select Project Backdrop, and click the Libraries tab. So click Add together External JARs, navigate to servlet.jar, and click OK. Doing so adds servlet.jar to the build path, as shown in Figure 4-18. Click OK to close the Properties dialog, and and so build the project; when you do, things will work out fine (and you'll run across servlet.jar in the Bundle Explorer).

servlet.jar in the build path

Effigy 4-18. servlet.jar in the build path

If you add multiple .jar files to the classpath, you as well can bespeak the order in which you lot want them searched. Just click the Gild and Export tab in the Backdrop dialog, and alter the order of imported items past using the Up and Down buttons.

Tip

If you know you're going to exist using a .jar file such as servlet.jar when you starting time create the project, you lot can add that .jar file to the projection's classpath in the 3rd pane of the New Project dialog. You'll see the aforementioned tabs there every bit you do in Effigy four-18. Just click the Libraries tab, and add the .jar files y'all desire to the project.

Creating classpath variables

If you know you're going to be using a .jar file such every bit servlet.jar often, you might want to create a classpath variable. Doing and then will salvage yous fourth dimension when y'all want to include items in a projection'due south build path. Using classpath variables similar this is not only convenient, but also information technology centralizes your classpath references for piece of cake treatment. For example, if y'all want to use a new version of servlet.jar beyond multiple projects, all you take to do is to update i classpath variable.

To create a classpath variable, select Window Preferences Coffee Classpath Variables, as shown in Figure 4-19. Click New, enter the new variable'south name—we'll employ SERVLET_JAR here—enter its path (or browse to its location), and and so click OK. You can run across this new variable in the figure.

Creating a classpath variable

Figure 4-19. Creating a classpath variable

Using classpath variables

When you want to add this classpath variable to a project's classpath, open up the project's Backdrop dialog, click the Libraries tab, click the Add Variable push (shown in Effigy 4-xviii), and select the variable you want to add together to the classpath.

How To Change Class File In Jar,

Source: https://www.oreilly.com/library/view/eclipse-cookbook/0596007108/ch04s12.html

Posted by: ortizfoophy.blogspot.com

0 Response to "How To Change Class File In Jar"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel