我现在已经拿到了一个ear包,我的工作只是往这个ear包里放2个.txt的文件,请问我怎么用eclipse来加载这ear包,加入文件以后怎么再生成一个ear包。
我试着用eclipse打开,但是有错误信息说 ‘IWAE0037E 无法打开 (让后就是文件的路径)’可以用rar直接往ear包里放文件么,可是我的rar说只能向rar或者zip文件里添加文件,请大家帮忙看看

解决方案 »

  1.   

    ear不可以解压么??只要能解压不就好办了。
      

  2.   

    用命令行,用ant,都行啊,再不会的话搞个java类,使用JarOutputStream
    /**
     * jar压缩指定文件或者文件夹到指定文件
     * 
     * @param inputFile
     * @param outputFile
     * @return
     */
    public static void jar(File inputFile, File outputFile) throws Exception
    {
    JarOutputStream out = null;
    try
    {
    out = new JarOutputStream(new FileOutputStream(outputFile));
    jar(out, inputFile, "文件夹");
    }
    catch (Exception e)
    {
    logger.error(e);
    throw e;
    }
    finally
    {
    try
    {
    if (out != null)
    out.close();
    }
    catch (IOException e)
    {
    logger.error(e);
    }
    }
    } /**
     * jar压缩的递归方式
     * 
     * @param out
     * @param f
     * @param base
     * @return
     */
    private static void jar(JarOutputStream out, File f, String base)
    throws IOException
    {
    if (f.isDirectory())
    {
    File[] fl = f.listFiles();
    base = base.length() == 0 ? "" : base + "/";
    for (int i = 0; i < fl.length; i++)
    {
    jar(out, fl[i], base + fl[i].getName());
    }
    }
    else
    { try
    {
    out.putNextEntry(new JarEntry(base));
    FileInputStream in = new FileInputStream(f);
    byte[] buffer = new byte[1024];
    int n = in.read(buffer);
    while (n != -1)
    {
    out.write(buffer, 0, n);
    n = in.read(buffer);
    }
    in.close();
    }
    catch (IOException e)
    {
    logger.error(e);
    throw e;
    }
    }
    }
      

  3.   

    用 eclipse ee 生成 ear1,新建一个工程   选择Java EE中的Enterprise Application Project
    2, 新建动态Web工程   Web -> Dynamic Web Project
    注意:Add project to an EAR 选项要打勾在下一行的ear project name 选第一步中新建的工程名3,右键web工程名 选择export -> java ee -> EAR File   在ear project选中第一步建的工程名, destiantion 添打包路径和名称.还要沟中overwrite existing file