maven 程序包com.sun.image.codec.jpeg不存在的解决方案

找到rt.jar和jce.jar上传到nexus的3rd party仓库,在pox.xml中引入依赖

<dependency>
            <groupId>jce</groupId>
            <artifactId>jce</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>rt</groupId>
            <artifactId>rt</artifactId>
            <version>1.0</version>
        </dependency>

  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        BufferedImage img = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);  
        Graphics g = img.getGraphics();  
          
        // 画背景  
        g.setColor(Color.PINK);  
        g.fillRect(0, 0, img.getWidth(), img.getHeight());  
          
        // 画干扰线  
        g.setColor(Color.GRAY);  
        for (int i = 0; i < 20; i++) {  
            g.drawLine(new Random().nextInt(W), new Random().nextInt(H),   
                    new Random().nextInt(W), new Random().nextInt(H));  
        }  
          
        // 随机生成四个数  
        g.setColor(Color.BLUE);  
        g.setFont(new Font("Courier New", Font.BOLD, 16));  
        String sAuthCode = "", sRandom;
        for (int i = 0; i < 4; i++) { 
            sRandom = CTable[new Random().nextInt(60)];
            sAuthCode = sAuthCode + sRandom;
            g.drawString(sRandom, 6 + i * 13, 17);  
        }
        // 将认证码存入session
        request.getSession().setAttribute("ValidCode", sAuthCode);
          
        // 向客户端输出  
        response.setContentType("image/jpeg");  
        try {
            ImageIO.write(img, "JPEG", response.getOutputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
        
      //  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(response.getOutputStream());  
       // encoder.encode(img);


你可能感兴趣的:(maven 程序包com.sun.image.codec.jpeg不存在的解决方案)