I am trying to build the project Sharpen by versant. I will start out that I don't know anything really about java and it's tools, hence why I am trying to build Sharpen(Java to C# converter). So I ended up building the project, but now I am left with a bunch of .class files in the bin directories.
How can I turn those .class files into a executable .jar file so I can run it? Sharpen is an eclipse plug in, so will I need to do anything extra, and will I have to manually remove files from their subdirectories in the bin folder and add them to the main bin directory?
Go to file->export->JAR file,
select "Export generated class files and sources" and make sure that your project is selected, and all folder
Related
I'm using VSCode for my IDE for Java. I have the Setting.json file configured to output my .class files to a directory called 'build':
"java.project.outputPath": "build"
My Project Folder/File Layout is as follows:
math
\src
Main.java
\lib
Math.java
\build <- This is where I want my .class files to be built keeping the same file structure as
in the src folder.
When I use
javac src\Main.java
The compiler writes the .class files in the .\src directory, but I'm telling it to write the output in the .\build directory. Any ideas what's going on?
I didn't see settings.json in the workspace directory structure you provided. I think this may be the cause of the problem.
"java.project.outputPath"
This setting only takes effect in the workspace scope.
You can create a folder named .vscode in your workspace, then create settings.json:
Add the codes in workspace settings.json: "java.project.outputPath": "build".
I fixed the problem. I was using the Command Line. VSCode only builds to the specified build path if the build command is run through the gui.
I need to turn in the .class file of a class from Eclipse. I managed to turn in the .java version of the file by clicking and dragging it into my browser, but I'm not sure where to find a .class file. I've read that I can find it in the "bin" but I have no idea where this is.
Thanks for all the help!
Generally, Eclipse projects have the following file system:
Proj/
.classpath
.project
src/
Foo.java
bin/
Foo.class
So, navigate to the Project folder, go to bin, and your classes should be right there.
If you are on a mac:
If you are in your project in the command line (you have done cd project)
You can do
cd bin
open .
And your class files should show up in a place that you can drag them into a browser. I don't understand why you need to submit .class files, as they are generated when the code is compiled.
Ctrl + Shift + T
will list down all the files including .class files in all of your projects in the workspace.
I apologize if this is an absolutely dunce question. I typically use Intellij Idea, and I'm not quite so familiar with Eclipse, so maybe this is part of my problem. I'm trying to compile a jar, I've done the export, as jar file, and checked "create .class files" in the output options, I click finish, and it "compiles" the jar file for me in the output.
I go to check the .jar file (open in Winrar) and the .jar file contains a folder named src, with all the .java source code, and there are no .class files in the .jar file. I figured maybe I could just change the file extension, because I thought maybe it just didn't change the extension, but when I got to view the file, it is clear that it hasn't even been parsed, as it is still in source format.
I receive no compile errors when I try to export it in Eclipse. I do have build errors for the entire project, but I'm not so worried about the entire project, I just wanted to compile one .jar file. And the build errors are not relating to the .jar file I'm trying to build, they are related to other files. Is it necessary to fix every build error to compile one .jar file? I'm just not quite sure why it would "compile" with no build errors, and then not actually compile.
Thank you in advance for any help!
Right click on your project > select Export... > select if your project is runnable or only JAR > check the option "Export Java source files and resources" > Finish
I'm writing a MP3 player in Java.
If i will finish I want to pack all .class files in one .jar file. I don't want have player, which starts by console.
If i open this one .jar file i want see player window.
I know how to pack it. I must use jar.exe packer with params: cvfm Player.jar MANIFEST.MF ./config/*.class and create MANIEST.MF which content class that has main method.
But the problem is when I want use another Look and Feel, or use existing .jar file. I can put this existing .jar file into my player main dir and compile javac.exe with parameter -cp .;./JarFile.jar, but when I pack all compiled .class files and my existsing JTattooDebug.jar file into one Player.jar file i don't see new Look and Feel i just see default view.
If you are using eclipse.
Right-Click your project
Export -> Runnable Jar File
Then select the destination for your jar, and make sure you have "Extract required libraries into generated JAR" selected. That will give you a runnable jar, complete with auto generated manifest, with all of your needed jars inside.
Solved! I had to add line:
Class-Path: lib/JTattooDebug.jar
in my MANIFEST.MF file, now all works.
I have a Java desktop app with gui.My app is using some xml files from the "export" folder. When I export the app into a runnable jar file, the app is not working properly, because the jar does not contain this xml files, or the path to the files is wrong.
Is there any possibility to export a Java app into an executable jar file from eclipse and to tell somehow to include an additional folder, with the same structure?
More information
My project is using some xml files, organized in the following hierarchy:
templates -> HASH CODE fgrtsgdtagsdnjf -> test -> document.xml
templates -> HASH CODE sgdtfhfnjnjcnjc -> test -> document.xml
When I export my project into an executable jar file I don't know how to specify to my app to use that files. I have FileNotFoundException.
So far, I succeed during export into an executable jar file to export that folders with XML files as well. So the files exists in the jar archive. but I do not how to indicate to use them in my project?
Since you said you get FileNotFoundException, I assume you are trying to use File, FileStream, FileReader or similar; you can't use those, you need to use class.getResourceAsStream() (search first in the the same directory as the class) or class.getClassLoader().getResourceAsStream() or getSystemResourceAsStream().
Eclipse packages the contents of the source folders (i.e. src, export and test) in the root of the JAR, so if you have "export/document.xml" you'd use 'MyClass.class.getResourceAsStream("document.xml")'. And remember to close the stream.
My app is using some xml files from the "export" folder.
If export folder has only required xml files, then just move it inside src folder. It would be automatically included once you Export as Executable Jar
Another option is to right click the folder and select Build Path, experimenting with it might help.
Is there any possibility to export a java app into an executable jar file from eclipse and to tell somehow to include an additional folder, with the same structure?
When you export as executable jar there is an option to save scenario as Ant script. Later you can modify it and Run as -> Ant