I am trying to deploy a JAR into Docker.
The problem I am running into is building the JAR. (with IntelliJ)
I clicked File -> Project Structure then went to 'Artifacts' and clicked the 'Create Archive' button.
I provided a name for the JAR ("SimpleService.jar")
I clicked CREATE MANIFEST and then the following have been done
Manifest File location is selected
Main class is set to com.oneorangetree.Main
Class Path is "C:\Program Files\Java\jdk-17.0.1\lib*.jar"
This is the first time I am trying to deploy a Java application. I am not sure what #2 and #3 should be set to.
Related
I have a Java Spring Boot/Maven application which I checked out into a workspace "C:\PA4Workspaces" from Subversion.
This was one of many projects which I checked out, including one with the name "ILCore".
Originally, the project in question defaulted to the name "ILCore (3)". I renamed "ILCore (3)" to something different, call it "MyAppServices".
MyAppServices has two sub-projects, one of which is named "Core".
I want to run the Spring Boot application in "Core". When I right-click and select "run as java application", it properly displays the class that launches the Spring Boot application at the top of the list of classes.
However, when I run it, it gets the error:
Error: Could not find or load main class
(1)\target\classes;C:\Users\xxxxx.m2\repository\com\mycompnay\bip\rest-server\1.5.0.0-SNAPSHOT\rest-server-1.5.0.0-SNAPSHOT.jar;
.
.
<many jar files from the repository>;
.
.
C:\PA4Workspaces\ILCore
It looks like the default path is "C:\PA4Workspaces\ILCore" instead of "C:\PA4Workspaces\MyAppServices\Core"
Is this the problem? If so, how do I fix it? Note the name in the .project file is correct. The name of the project in the part .project file is also correct, although I had to manually change it from the original name.
Step1: Right click on project,select maven -> update project as shown below from below context menu image.
Step2: Then make sure the Force update of screenshots/release checkbox should be ticked as shown in below image
Step3: click Ok and now try to re-run the application and it could probably solve your error.
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 have a java package with many java class and many main. i wish to make jar from these package ? can you help me please ?
(i work with netbeans )
If the project is under netbeans IDE, you should follow these steps:
Right click on the project and then click on Properties
Click on Packaging
Click on Compress JAR File
Accept changes, click OK
Right click on the project and then click on Clean and Build
Go to the directory where your project is stored
Look in the dist folder for the JAR file
To select the main class that will be executed
Click on Run
Click on Browse near to Main Class label
EDIT :
If you are using netbeans under windows, and if the jar file does not generate any output, try the following command in cmd :
start /b <jar file>
Then an error should appear
So you can know what is the problem
Right click on the the project in net beans project window and choose Project Properties -> run , there you can setup your main class
clean and build your project and go to your netbeans project -> your project -> dist there is the executable jar file.
selected main class will be executed when you execute the generated jar file
I found this site useful... Hope it helps
deploying jar
I have a small piece of code that works correctly in its own project (it is just a file selection dialog). I wanted to use it in my larger project, so I exported the FileSelector as a jar by doing the following:
Right click on the FileSelector project and click 'Export'
Select Java -> JAR file
Set the 'export destination'
Click 'Finish'
Copy the exported .jar file into MyProject/libs
Right click on MyProject -> Refresh
Right click on MyProject -> Properties
Click 'Java Build Path'
In the 'Libraries' tab, click "Add JARs" and select the .jar file I just copied into MyProject
I was getting the error "Error generating final archive: Found duplicate file for APK: AndroidManifest.xml", so I just unselected AndroidManifest.xml from the list of files to export to the jar and created it again.
MyProject seems to build fine, but when I run it and click the button that should display the file selection dialog, I get a null pointer exception. I went back and tracked it down in the FileSelection code, and it is a simple
mFilterSpinner = (Spinner) mDialog.findViewById(R.id.fileFilter);
that is returning null. Is there something I have not done in the project setup that will allow a call like this to work from inside a jar? Or is there something wrong with my procedure for packaging up and importing the jar?
Values in R class would be modified. So, you can't find your view when using compiled R inside your Jar.
The only solution is using android library project and reference resources and sources through it. Otherwise, you can referencing it by making your android library project into AAR archive.
if you are using Android UI components, I think you should be using it in another project as an Android library.
I want to create a jar file in Netbeans using the clean and build options. The jar file is created, but the manifest file is not updating; this means the main class is not set in the manifest file, so when I run the jar file, it has the "could not load main class" error.
How do I handle this and how do I add main class in project properties?
Right click on netbeans project and select "Properties"
Then select "Run". There is option for selecting main class. Select main class from there.Then click "ok".
After doing this try run your project at least once before building your jar file.
Hope You did not set up main class in project setup.
So do right click on project.
then go to properties.
On that screen you can see Run configuration.
There is place to configure main class of you jar file.
So configure your main class at there and press ok.
Then clean and rebuild the project.
After that manifest file should update.
May be you are running your project using shift+F6 key. You should run your project once by pressing F6 key only then the netbeans gives option to select main class then after that clean and build.