I want to put my java Project in a .jar or in an .exe. I can not find a solution for my problem.
That is my project structure:
project
1.1. pom.xml
1.2. .idea
1.2.1. libaries
1.2.1.1. many maven dependency files
1.3. .GUI
1.3.1. .idea
1.3.1.1. libaries
1.3.1.1.1. many maven dependency file
1.3.2. src
1.3.2.1. main
1.3.2.1.1. java
1.3.2.1.1.1. .java files
1.3.2.1.2. recources
1.3.2.1.2.1. .fxml files
1.3.2.1.2.2. CSSStylesheets
1.3.2.1.2.2. .css files
I follow instructions on youtube for creating a .jar in Intellij (https://www.youtube.com/watch?v=ZlyTn8PZ3Fc) but the .jar was not executable. It just print this Display parameters as parsed by Maven (in canonical form) and comparison result: to the console after running java -jar file.jar. (After the double dot there does not come more information.)
Next I found another youtube video that shows me it does not work like in the first video because of the maven dependencies (https://www.youtube.com/watch?v=HGHu-SzL-5E). In this video I do not know what to do in 5:39. He copies something but I do not know from where that is. I tried to put the same files in there like he did but it does not work. There comes a ClassNotFoundError that it can not be found the .fxml files. Then I do not write them in the command but all other .java files but it was the same error.
On this (https://introcs.cs.princeton.edu/java/85application/jar/jar.html) site I had my next try. I follow the instructions like this: I dreated a .mf file and put all .fxml and .java and .class files in the command but it can not be found the .class files so I put them out of the command. And then ist comes a ClassNotFoundError. It can not find the Main class. Intellij mark it in the .mf file red as well and I do not know why.
Then I follow the instructions of this (https://cwiki.apache.org/confluence/display/MAVEN/Tutorial%3A+Build+a+JAR+file+with+Maven+in+5+minutes) site but there an empty .jar file was created.
Now I do not know what I did wrong or what I miss so I hope someone can help me.
Related
I have a question, perhaps it was already answered, but i didn't manage to find it and I appologize if the solution already exists (let me know if it is before deleting my thread).
Problem is:
I have created a program on another PC and exported it from eclipse as a .jar file. It works on my main PC when I double click on it but when I import it in Eclipse I can't find the .java file. So i can't edit it.
What I have done so far:
In eclipse I have created a new empty project
I have right clicked,import, archive file, selected the .class files that eclipse sees, but when I am in the Project Explorer in Eclipse I can't find the .java file where the main is. I mean I can click run as a program and it works, but there is no .java file, only .class files. What am I doing wrong?
That cranes.class should be cranes.java. At least on my other PC it is.
Program works fine, but I can't edit it on my main PC. What am I doing wrong?
Thanks and best regards
You need to select the Export Java source files and resources option while creating the jar file and then your Java files will be available on importing the project from the jar file.
This is similar to how you use other libraries. You depend on the Jar file which contains class bytecode (compiled) of java code. You can't edit any of such files directly in the project you are using it. Thought you can always extends functionalities in your current project using simple inheritance concepts.
If you think such functionalities are trivial you should prefer to change in the original project rebuild the jar and use the newer version of jar.
However if you feel similar things for 3rd party library you can
always make changes after taking fork from those library source
code (if open source) and build and use your own version or go
ahead and raise pull request if you are confident about your
changes.
Mostly when you build a jar file, all you have in it are .class files; these are the result of compiling .java files, and so are not editable with text editors.
You CAN create a jar file that contains .java (also known as source) files, and even a jar file that contains both .java and .class files, but if you ask eclipse to create a jar file, by default it is just going to put .class files and files from resource folders in it, not .java files.
Assuming from the question, the jar is a library created by OP, by compiling java files into class files and packing/exporting them. Although the class files can't be edited in any IDE, they can be de-compiled into Java files by using third-party applications.
I personally use IntelliJ for this de-compiling source files authored by me
Note: Although this gives OP the desired functionality, it may lead to violations if the classes are Copyrighted.
As IntelliJ states, they neither encourage nor discourage de-compiling class files and the decision is purely to the user's discretion.
EDIT: It is always recommended to use the original source files for editing. Try to host them on git so that it may be retrieved anytime required
It may be simpler to not use eclipse but jar/zip/tar your project directory on the one computer and simply extract it onto the other, then open that folder as a new project in Eclipse.
Best is the suggestion from #SanjayBharathi to use git and clone the repo on your other machine.
I wrote a program that spans a few classes in IntelliJ and it works fine when I was testing it in the IDE. However, whenever I follow tutorials to make my project into a .jar executable, it does not run.
The file in the out folder does not run when double-click on it and says "The Java JAR file "projectName.jar" could not be launched.
When opening it from the terminal, I get the error "Could not find or load main class". I used "$ java -jar projectName.jar "
I followed these steps:
Open Project Structure, Artifacts and click the (+).
Under JAR, from modules with dependencies.
Point to the class with my main method and click OK.
Click apply and OK to exit.
Then I close project structure and open Build and then Build Artifacts...
Then I click Build.
Navigate to ~/IdeaProjects/projectName/out/artifacts/projectName_jar/projectName.jar
Then I would try to run it but it does not run. My project has both a GUI and can be run from command lines. When I compiled the main method in Terminal, it worked fine, but I need a JAR file. I'm not sure what I should include in the question, since I'm sure that my code is unrelated. I also utilize Maven, not sure if that is related. Are there other things that I should be doing or adding to my project before I build the JAR?
This can be a result of the Manifest being created in the wrong place.
First make sure it is in src/main/resources/META-INF/MANIFEST.MF
(Intellij sometimes incorrectly places it in /src/main/java/META-INF/MANIFEST.MF)
Then Make sure the jar is looking for META-INF in the src dir NOT in /java OR /resources. This means:
When you set up File>Project Structure>Artifacts>+>JAR>From modules with dependencies... then your Directory for META-INF/MANIFEST.MF should end at src. Example:
ONLY C:\Users\User\StudioProjects\Project\src\
NOT THE PREPOPULATED C:\Users\User\StudioProjects\Project\src\main\java
If your Project Structure jar is already set up change the Manifest File path to:
C:\Users\User\StudioProjects\Project\src\META-INF\MANIFEST.MF
INSTEAD OF C:\Users\User\StudioProjects\Project\src\main\java\META-INF\MANIFEST.MF
You need to make sure that the Main-Class attribute is set. One way to check this is by opening the Jar with a Zip utility and looking for META-MF/MANIFEST.MF extract or open that file with a notepad, notepad++ or any document reader. If "Main-Class" is not in their or set to the correct main class you will received the error you have received. Seeing the IntelliJ tutorial it has a Main-Class field when setting up artifact publishing. I have included the link below to the IntelliJ page.
IntelliJ Creating an Artifact Tutorial
I want to use the included tile packager from osmdroid's solution to use maps offline since Mobile Atlas Creator didn't work for me (I want 16x zoom levels which is not possible using this tool).
The instructions say that should run a .jar file using a command line, but there are no .jar files in the package and there are only source code files which when I run with netbeans IDE, gives me an error about unresolved dependency issues.
Anyone have any suggestions on how I can do this?
The answer given here didn't work for me as the .jar file always gave me a manifest (main class) error. So what I ended up doing was:
Download the project from github
run a 'gradle build' in the top folder (you can comment out the included libraries in the settings.gradle file if there is any problem with the Android SDK and you only need to use the tile packager)
run a 'gradle run' in the OSMMapTilePackager folder
by now gradle should have generated the following folder: OSMMapTilePackager/build/distributions/ and inside that folder you should have a zip file called something like OSMMapTilePackager-5.6-SNAPSHOT.zip. Unzip it
Go to the bin folder and run ./OSMMapTilePackager -gui
A window should have opened asking you for the parameters to download the tiles.
Got the procedure from this issue discussion.
Hope this helps anyone.
Just call gradle compileJava in OSMMapTilePackager directory. The jar should be in the tagret directory.
I created a project in Netbeans 7.1 on my netbook which uses Windows XP. I used the Clean and Build command which created the distributable JAR file in the /dist folder. When I double clicked the file it worked.
Now I sent the entire project folder to my desktop, which uses Windows 7 Ultimate 64 bit. When I double clicked the executable JAR I got an error saying:
Could Not find or load main class myapp.jar
I checked the manifest file and it contains the main class name. Of course, it was autogenerated by Netbeans.
What is going on?
The common mistake is to forget to also take the "layout" folder. If you have used specific features of Netbeans, such as bindings, in the "dist" you have the jar but also a folder with the name "layout" in it and you must also copy it with the jar file and put it at the same target place.
In my case it was a pity having to also send this folder so I decided to stop using binding and other specific stuff and used to reprogram things by hand. Now I only send the jar and it is working.
Note that you can easily know if you have specific features.
Open Netbeans and look in your project folder. There you'll have 2 folder, "Source Packages" and "libraries". Check in libraries. If you have only the JDK it is ok. If you have other libraries listed, then there will be the supplementary folder in the dist and you will have to send it with the Jar.
Hope it helps
I want to add DLL's, images, textfiles etc to my project as resources so when I export it, the jar contains the resources so they can be used. I am using eclipse.
Problem is I have no idea how to add it. I've tried adding DLLs/pics to the src folder in the project, but when I export the jar, it is not located there
I've looked at How to make a JAR file that includes DLL files? but it only explains how to extract it, not how to add it to the project and build.
EDIT: I am using an applet to open the jar by the way, sorry for missing it!
Cheers
How are you opening the file in java?
Class.getResourceAsStream(name)?
If you are packaging the code in a jar, then you need to use that command. (as opposed to new File(name), which will get the file in the same directory as your jar)
If the file is not physically in your jar, you can check by changing .jar to .zip and extracting it, then check out this doc http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
Usually in an eclipse project, the src folder is the wrong place to put non-sourcecode-content.
You should try moving to maven as your build system, as it is highly customizable and provides you with folders inside your project for exactly that purpose. (src/main/resources)