Results 1 to 3 of 3
- 11-23-2010, 09:48 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
How to execute a class in a subdirectory in .jar file
Dear All,
I have a jar file "My.jar".
In this "My.jar" file, I have a directory "build\classes".
In this "build\classes" directory, I have a package "package1.sub1".
In this "package1.sub1", I have class files "MyClassA.class", "MyClassB.class", etc. (package package1.sub1 is declared in all of these classes.)
Now, I want to execute "package1.sub1.MyClassA.class" in "build\classes" directory of "My.jar" from the command line. How can I do that?
I tried "java -cp My.jar build\classes\package1.sub1.MyClassA.class", but it was not successful. Please help me.
Thank you very much.
Best regards,
Zeyar
- 11-23-2010, 02:44 PM #2
I'm not sure why you would package the build/classes folder into the jar file.?
Usually you would create the jar file with the build/classes as the base directory, so that the first folder inside the jar file would be package1/ and then the command line "java -cp My.jar package1.sub1.MyClassA" (also without the .class extension) would just work.
In theory it is technically possible to get the files inside build/classes inside the jar file to work, this can be done by creating a bootstrap piece of Java code that lives in the top level of the jar file that unpacks the jar file to a temporary location and then installs a URL class loader kind of class loader to refer to the build/classes/ where it now exists in this temporary folder to have it added onto the classpath. But unless there was a very compelling reason to do this, I would say just change how you build your jar file to have the build/classes be the jar root.
For example, in Ant,
Java Code:<target name="make-jar"> <jar jarfile="My.jar" basedir="build/classes" /> </target>
- 11-23-2010, 05:49 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
How to execute a .class file from a Rightclick
By Norm in forum Suggestions & FeedbackReplies: 0Last Post: 09-09-2010, 09:58 PM -
jar file won't execute.
By Splat in forum New To JavaReplies: 5Last Post: 10-22-2009, 05:26 AM -
How to use Timer class to schedule a task to execute once 5 seconds have passed
By Java Tip in forum java.utilReplies: 0Last Post: 06-26-2008, 07:32 PM -
how to rename a subdirectory
By richardzhang in forum New To JavaReplies: 0Last Post: 08-10-2007, 04:28 AM -
Execute Jar file
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks