I am trying to write a batch file that writes the classes-dex2jar.jar to some other folder.
I tried the following:
d2j-dex2jar %arg1% -o %arg2%
Here, arg1 is the path to classes.dex and arg2 is the folder where I wish to store the generated classes-dex2jar.jar file. (E:\new\)
Now, I am getting FileNotFoundException for the second argument. It says
java.io.FileNotFoundException: E:\new" (The filename, directory name,
or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:77)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:250)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java
:110)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:174)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:34)
Please tell me what am I doing wrong?
Instead of passing the folder as an argument, pass it the jar filename.
d2j-dex2jar classes.dex -o "E:\new\classes.jar"
Also make sure E:\new directory exists. Dex2jar does not create a new directory. Create a directory and then pass d2j-dex2jar the full path to the directory plus the jar file name you want.
java.io.FileOutputStream.open - looks like you'are trying to open directory with FileOutputStream , which should be not possible.
Related
I have used
File file = new File(Game.class.getResource("Tiles.txt").getFile())
to get the txt file from my resources folder and it works fine when inside the IDE but when building to a jar and running outside of the environment it throws file not found errors (which i saw through running in CMD).
I use a similar method to get all my images and sprite sheets:
BufferedImage loadedImage = ImageIO.read(Game.class.getResourceAsStream("EG.png"));
how do they differ in importing files and why is my path incorrect?
Error CMD gives:
http://imgur.com/a/1SC1L
C:\Users\Taka\Desktop>java -jar ProjectC-Revamped.jar
java.io.FileNotFoundException: file:\C:\Users\Taka\Desktop\ProjectC-Revamped.jar!\Tiles.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Tiles.<init>(Tiles.java:16)
at Game.<init>(Game.java:91)
at Game.main(Game.java:192)
java.io.FileNotFoundException: file:\C:\Users\Taka\Desktop\ProjectC-Revamped.jar!\Maps\Map.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Map.<init>(Map.java:20)
at Game.<init>(Game.java:94)
at Game.main(Game.java:192)
use getResourceAsStream() instead of getResource(): see this SO answer for details
URL.getFile() does not convert a URL to a file. It merely returns the path and query portions of the URL. The method is named getFile() only because the URL class was part of Java 1.0, which was released in 1995, back when most URLs happened to point to actual files.
The path returned by URL.getFile() returns a String which may or may not be a valid file path. Many characters may not legally appear in URLs, so they will be percent-escaped. A good example is spaces; for example, file:///C:/Program%20Files/Java.
In short, converting a URL to a file using getFile() is not safe and will eventually fail.
Also, an entry in a .jar file is not a file. A .jar file is a single archive file. Its entries are just subsequences of bytes (representing compressed data). On the other hand, the URL returned by getResource is always valid (assuming it’s not null), even if it represents a .jar entry.
C:\Users\sunka\Desktop\CS DEPT\fall 2k16\information structures>jar
-xvf week2.zip
java.io.FileNotFoundException: week2.zip (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at sun.tools.jar.Main.run(Main.java:307)
at sun.tools.jar.Main.main(Main.java:1288)
When I am trying to unzip using jar -xvf, I am getting file not found exception. I used the same command in my office, it was working. I made sure that zip file and jar file are present in the directory.
Check if you in same directory where you have zip file placed.
Because if JAVA path is set properly and your are giving right zip file name with correct path it works fine.
how do I create an archive "classes.jar" which should contain 2 files ".class" (named as MyFirstClass.class and MySecondClass.class) using file I created "manifest.mf".
This must be done using the program javac, program jar and cmd.
2 files .class I already got using javac program.
This is all located in the folder C:\Task7
MyFirstClass.class file located in the folder C:\Task7\myPackage (because it is in the package "myPackage")
MySecondClass.class file located in the folder C:\Task7\myPackage\myfirstpackage (because it is in the packages myPackage and myfirstpackage)
myManifest.mf file located in the folder C:\Task7
My attempts to:
1) C:\Program Files\Java\jdk1.7.0_51\bin>jar cvfm classes.jar C:\Task7 manifest -C C:\Task7 myPackage.MyFirstClass.class myPackage.myfirstpackage.MySecondClass.class
cmd answer:
java.io.FileNotFoundException: C:\Task7 (Mbp4p3m r •meCesix)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at sun.tools.jar.Main.run(Main.java:171)
at sun.tools.jar.Main.main(Main.java:1177)
2) C:\Program Files\Java\jdk1.7.0_51\bin>jar cvfm classes.jar C:\Task7 manifest C:\Task7\myPackage\MyFirstClass.class C:\Task7\myPackage\myfirstpackage\MySecondClass.class
cmd answer:
java.io.FileNotFoundException: C:\Task7 (Mbp4p3m r omeCesix)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at sun.tools.jar.Main.run(Main.java:171)
at sun.tools.jar.Main.main(Main.java:1177)
3) C:\Program Files\Java\jdk1.7.0_51\bin>jar cvfm classes.jar C:\Task7 manifest C:\Task7\myPackage MyFirstClass.class C:\Task7\myPackage\myfirstpackage MySecondClass.class
cmd answer:
java.io.FileNotFoundException: C:\Task7 (Cbpgrosm r omeCegx)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at sun.tools.jar.Main.run(Main.java:171)
at sun.tools.jar.Main.main(Main.java:1177)
What am I doing wrong?
Keep all the file in a folder and Go to that location and use the following command-
jar -cvf abc.jar abc
if your folder name is abc.
If you run jar out of dir your class hierarchy is located, you shoud use -C option before the list of files. In your case it should be: -C C:\Task7
I have a SoapUI project running through a java project that is all packaged into a jar. The project runs fine unpackaged through my IDE, but it encounters problems when running the jar through the command line. Here is the code that is causing the problem:
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
ClassLoader cl = MyClass.class.getClassLoader();
runner.setProjectFile(cl.getResource("project.xml").getFile());
runner.run();
The problem occurs on the run method when it tries to read in the xml file from the jar. Is it possible for me to get a path that I can input to the setProjectFile method from the jar? I've seen other answers say to use a stream, but this method only accepts strings.
Here is the stack trace:
2014-07-23 12:03:58,384 ERROR [errorlog] com.eviware.soapui.support.SoapUIException: Failed to load project from file [file:/C:/temp/MyJar.jar!/project.xml]
com.eviware.soapui.support.SoapUIException: Failed to load project from file [file:/C:/temp/MyJar.jar!/project.xml]
at com.eviware.soapui.impl.wsdl.WsdlProject.loadProject(WsdlProject.java:315)
at com.eviware.soapui.impl.wsdl.WsdlProject.(WsdlProject.java:231)
at com.eviware.soapui.impl.wsdl.WsdlProjectFactory.createNew(WsdlProjectFactory.java:41)
at com.eviware.soapui.impl.wsdl.WsdlProjectFactory.createNew(WsdlProjectFactory.java:28)
at com.eviware.soapui.tools.SoapUITestCaseRunner.runRunner(SoapUITestCaseRunner.java:329)
at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:188)
at CommercialTests.ComTest.doTest(ComTest.java:14)
at CommercialTests.ServiceTests.main(ServiceTests.java:8)
Caused by: java.io.FileNotFoundException: C:\temp\MyJar.jar!\project.xml (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader.handleFile(UrlWsdlLoader.java:180)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader.load(UrlWsdlLoader.java:116)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader.load(UrlWsdlLoader.java:96)
at com.eviware.soapui.impl.wsdl.WsdlProject.loadProject(WsdlProject.java:297)
... 7 more
For something like this I normally do:
URL res = getClass().getResource("/project.xml") // is it at the root of your jar?!?!
File f = new File(res.getFile())
runner.setProjectFile(f.getCanonicalPath());
SoapUI, depending on how it accesses the file, might need it in the "real" world. Below is a much more resource-intensive version of the above.
// locate your file in the jar resources
URL res = getClass().getResource("/project.xml") // is it at the root of your jar?!?!
// locate the resource in the filesystem
File f = new File(res.getFile())
// copy the file out into the real filesystem
File target = new File(System.getProperty("java.io.tmpdir") + File.separator + f.getName())
java.nio.file.Files.copy(f.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING)
runner.setProjectFile(target.getCanonicalPath())
I'm writing a java program for class that reads in from a txt file. I placed the text file in the package called Assignment3pckg and use a scanner like so:
Scanner s = new Scanner( new File("./src/Assignment3pckg/studentdata.txt") );
But it just keeps giving me
java.io.FileNotFoundException: .\src\Assignment3pckg\studentdata.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Assignment3pckg.TestHW3.readStudentDataFromFile(TestHW3.java:25)
at Assignment3pckg.TestHW3.main(TestHW3.java:14)
Any insight would be greatly appreciated!
You are using a relative path (as opposed to an absolute path) for your file. Relative paths are resolved relative to the current working directory of the Java process when you run it.
Where this directory is depends on how you run Java.
You can find out by printing it:
System.out.println(new File(".").getAbsolutePath());
You can resolve it by:
Making your path relative to the correct directory
Using an absolute path (on Windows, that would start with C:\ or another drive letter)
Note though that in Java, you have to escape backslashes in a String. So C:\myproject\src\Assignment3pckg\studentdata.txt becomes "C:\\myproject\\src\\Assignment3pckg\\studentdata.txt" as a Java String. Or "C:/myproject/src/Assignment3pckg/studentdata.txt" as Windows doesn't mind forward slashes instead of backslashes either.