내 응용 프로그램에서 파일/폴더를 템플릿 zip에 추가하고 사용자가 지정한 위치로 zip을 이동하려면 TrueZip을 사용하고 있습니다. Netbeans에서 응용 프로그램을 실행하거나 명령 프롬프트에서 .jar을 실행하면 원하는대로 모든 것이 작동합니다. 사용자가 zip "test"라는 이름을 지정하면 "test.zip. {random-number} .tmp"라는 test.zip 및 tmp 파일이 만들어지고 두 파일이 생성되고 응용 프로그램이 닫히면 tmp 파일은 제거되었습니다.netbeans/jar에서 실행하면 TrueZip이 올바르게 작동하지만 javaw는 실행되지 않습니다.
Java Web Start를 사용하여 웹 서버에 응용 프로그램을 배포하고 실행하면 두 파일이 다시 만들어 지지만 응용 프로그램이 닫히면 tmp 파일이 제거되지 않고 생성 된 zip 파일을 열려고 할 때 "아카이브가 알 수없는 형식이거나 손상되었습니다"라는 메시지가 표시됩니다.
netbeans 또는 .jar에서는 제대로 작동하지만 웹 시작에서는 작동하지 않는 이유를 알 수 없습니다.
코드 우편을 만드는 클래스를 호출 :
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.addChoosableFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
}
if(file.getName().toLowerCase().endsWith(".zip")) {
return true;
}
return false;
}
@Override
public String getDescription() {
return "*.zip";
}
});
int rVal = chooser.showSaveDialog(this);
if (rVal == JFileChooser.APPROVE_OPTION) {
try {
//Get savepath and ensure it ends with .zip extension
String savePath = chooser.getSelectedFile().getCanonicalPath();
if (!savePath.endsWith(".zip")) {
savePath = savePath.concat(".zip");
}
PackageBuilder build = new PackageBuilder(groups, calibData);
build.buildZip(savePath);
} catch (IOException ex) {
System.out.println(ex);
}
}
PackageBuilder의 클래스 :
package apkinstallingaromacreator;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileWriter;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
public class PackageBuilder {
private File workingArchive;
private AromaConfigBuilder aromaBuilder;
private UpdaterScriptBuilder updaterBuilder;
private ApkGroup[] groups;
public PackageBuilder(ApkGroup[] groups, String calibData) {
workingArchive = new File(System.getProperty("java.io.tmpdir"), "aromabuild.zip");
aromaBuilder = new AromaConfigBuilder(groups, calibData);
updaterBuilder = new UpdaterScriptBuilder(groups);
this.groups = groups;
//Get template.zip from jar package and move it to system tmp directory
URL templateUrl = getClass().getResource("resources/template.zip");
try {
FileUtils.copyURLToFile(templateUrl, workingArchive);
} catch (IOException ex) {
System.out.println("Failed to copy template zip from resources");
Logger.getLogger(PackageBuilder.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void importApkFiles() {
//For each Apk in each ApkGroup add Apk file to zip in system tmp directory
//If Apk doesn't list a file, create an empty directory for adding manually
for (int x = 0; x < groups.length; x++) {
Apk[] apks = groups[x].getApkArray();
for (int y = 0; y < apks.length; y++) {
if (apks[y].getApkFileLocation().isEmpty()) {
TFile dir = new TFile(workingArchive, "data/" + apks[y].getApkName());
dir.mkdir();
}
else {
TFile src = new TFile(apks[y].getApkFileLocation());
TFile dst = new TFile(workingArchive, "data/" + apks[y].getApkName() +
"/" + apks[y].getApkName() + ".apk");
try {
src.cp_rp(dst);
} catch (IOException ex) {
Logger.getLogger(PackageBuilder.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
public void buildZip(String savePath) {
//populate aroma-config file within template.zip
File aroma = new TFile(workingArchive, "META-INF/com/google/android/aroma-config");
try {
Writer aromaWriter = new TFileWriter(aroma);
aromaWriter.write(aromaBuilder.buildConfig());
aromaWriter.close();
} catch (IOException ex) {
Logger.getLogger(PackageBuilder.class.getName()).log(Level.SEVERE, null, ex);
}
//Populate updater-script file within template.zip
File updater = new TFile(workingArchive, "META-INF/com/google/android/updater-script");
try {
Writer updaterWriter = new TFileWriter(updater);
updaterWriter.write(updaterBuilder.buildConfig());
updaterWriter.close();
} catch (IOException ex) {
Logger.getLogger(PackageBuilder.class.getName()).log(Level.SEVERE, null, ex);
}
importApkFiles();
//Copy the zip from system tmp directory to user specified location
TFile src = new TFile(workingArchive);
TFile dst = new TFile(savePath);
try {
src.cp_rp(dst);
} catch (IOException ex) {
Logger.getLogger(PackageBuilder.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
'TVFS.umount()'호출이 트릭을 수행했습니다. 도움과 개선 팁을 가져 주셔서 감사합니다. – osafi
내가 도울 수있어서 기쁩니다! –