• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Jar Format

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

For my data structures class I am required to submit my work in a .jar format. I have only had one Java coding class and this was something that was not covered. We were only required to submit .java files. I actually submitted a couple of assignments already and I was informed by my instructor that he could not read my source code. I followed instructions I found online on how to create a .jar file but I am not sure what I am missing. I use Netbeans. Is anyone able to walk me through the process of creating a .jar file that is executable? It would be much appreciated.

Thanks.
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post a link to the instructions that you tried, details of what you did, what you expected, and what you got instead (locations of files, dir listing, and anything that might help others get a better sense of the context in which you are seeing a problem). If you deviated from the instructions slightly, explain how and why.
 
Marshal
Posts: 80649
475
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NetBeans probably has an option somewhere which will create a .jar file from your project. Not just probably, but it certainly has such an option.
 
Sheriff
Posts: 28398
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:NetBeans probably has an option somewhere which will create a .jar file from your project.



That's true, but in the vast majority of cases the purpose of the .jar file is to be an executable file, i.e. a tool for running the project. So as such it normally wouldn't include source code. I haven't used that NetBeans tool but I expect you would have to do something out of the ordinary to cause the source code to be included in the .jar file.

Of course I have no idea what the OP did either, so what we're saying here might well be totally useless.
 
Christopher Calderon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got my instructions from here:

https://netbeans.org/kb/articles/javase-deploy.html

I don't understand the "grep" and "xgrep" parts of these instructions. Maybe I have to add the grep class to my project? I believe this is what is throwing me off. I wrote my code and it works fine in Netbeans. I created a .jar file from my project but nothing happens when I double-click it. This is my code so you all have an idea of what is supposed to happen:




It's frustrating because my assignments are late now : / I do understand, however, that he should be able to easily open and get the information he needs to grade my assignment. Of course sharing my code should be seamless for the recipient. This process of creating a .jar does seem quite convoluted, more than it should be maybe.

 
Paul Clapham
Sheriff
Posts: 28398
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So it's as I suspected. You're following instructions which are supposed to produce an executable jar, and (naturally) they don't include the source code. But your instructor wants the source code.

Have you considered asking your instructor how to make the required jar file? It doesn't seem fair to ask beginners to figure out things like this which use concepts which aren't usually taught in the first 50 minutes of an introductory programming course. (I'm assuming there that "one Java coding class" means "one lecture" and not "one semester of lectures" -- you might want to clarify.)

 
Christopher Calderon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The instructor isn't the most helpful. He told us we can email him, but it doesn't mean he will respond. He expects us to know how to code (at a beginner level) in at least Java, C, or C++. The course I took was a summer course on Java only at a community college. This is why I am posting in the beginner section.

Would trying to create a Windows .exe file be better in my situation? In my syllabus it says the following:

"A softcopy of the source code and the executable are to be turned in for each assignment. Executables must be either a Microsoft Windows exe or a Java jar file."

Upon reviewing this statement, I may have been incorrect about him being able to view the source code from just the .jar file.
 
Paul Clapham
Sheriff
Posts: 28398
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Calderon wrote:"A softcopy of the source code and the executable are to be turned in for each assignment. Executables must be either a Microsoft Windows exe or a Java jar file."

Upon reviewing this statement, I may have been incorrect about him being able to view the source code from just the .jar file.



Yes... it looks like you assumed the source code had to be inside the executable. So from the instructor's point of view, you've sent them the executable but not the source code. I'm not sure what would qualify as a "softcopy" of the source code though. Perhaps just attaching all of the .java files to the e-mail along with the .jar file, or something? The instructions don't appear to say the source code has to be packaged in any way.
 
Christopher Calderon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that was my mistake. He still needs an executable file to test the code. In the example I posted, he would input a sentence to test it. For clarification, the assignment was to write some code that would print out the words in a sentence on separate lines and double any number that was input.
 
Christopher Calderon
Greenhorn
Posts: 9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally found a solution. I found a program named Jsmooth. It's a Java executable wrapper. With it I was able to convert my .jar files to .exe files.

From what I gathered in searching for a solution, the problem I was having may have been mostly due to the fact that I didn't have a GUI. I was trying to make an executable with just text. It seems that C++ IDEs are usually equipped to do this, I think. My instructor's background is in C++ I believe. Well, I hope if someone else is having the same issue he/she checks out Jsmooth. Thanks for your input everyone.
reply
    Bookmark Topic Watch Topic
  • New Topic