私は検索して検索したので、私が本当に困惑していると言うとき、私を信頼してください. 注: Java 6 の使用を余儀なくされています。
Java を使用してプログラムで XML ファイルを zip アーカイブに挿入する必要がありますが、アーカイブを抽出して再圧縮する必要はありません。問題の解決策として Truezip を指摘されましたが、Truezip に「archive.zip」がアーカイブであることを認識させることができないようです。次の方法でアーカイブ インプレースにアクセスしようとすると、「archive.zip/file.txt はディレクトリではありません」というメッセージが表示されます。
new TFile("example.zip/audit.xml")
Truezip ブログと StackOverflow に関するいくつかの質問を参照しましたが、私がやろうとしていることを示すコードのサンプルが見つかりません。そのような単純なタスクを実行するスニペットを提供/指摘できる人はいますか?
完全なスタック トレース:
java.io.FileNotFoundException: /Users/ss042306/java-scan-example/target/fortify/example.zip/audit.xml
at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
at de.schlichtherle.truezip.file.TFileOutputStream.<init>(TFileOutputStream.java:116)
at com.fortify.ps.maven.plugin.sca.ScanMojo.copyPreviousComments(ScanMojo.java:745)
at com.fortify.ps.maven.plugin.sca.ScanMojo.execute(ScanMojo.java:332)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.nio.file.NoSuchFileException: /Users/ss042306/java-scan-example/target/fortify/example.zip/audit.xml
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
at java.nio.file.Files.newOutputStream(Files.java:216)
at de.schlichtherle.truezip.fs.nio.file.FileOutputSocket$1OutputStream.<init>(FileOutputSocket.java:243)
at de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.newOutputStream(FileOutputSocket.java:257)
at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:143)
... 24 more
次のリソースを参照しました。
[1] http://illegalexception.schlichtherle.de/2011/07/26/appending-to-zip-files/
[2] TrueZip を使用してファイルを zip に追加する
[3] https://truezip.java.net/kick-start/tutorial.html
編集: .zip ファイルを仮想ディレクトリとして扱うために必要なすべての依存関係がなかったため、Truezip は説明どおりに機能しませんでした。以下のスニペットを pom.xml に含めた後、ZIP ファイルを仮想ディレクトリとして操作できるようになりました。
` <dependency>
<groupId>de.schlichtherle.truezip</groupId>
<artifactId>truezip-driver-zip</artifactId>
<version>7.7.9</version>
</dependency>`
この依存関係がなければ、「.zip」をアーカイブとして識別するために利用できる TArchiveDetector はありませんでした。