I just developed an application in java and I need to handover the code partially.
So, what is I want to achieve is
I've a class manageTask.Java at com.project.users.manageTask and As I need to handover the source code, excluding one class file, I want to create a jar file for that class and use with same project instead of that manageTask.Java
Somebody Please guide
Edit:
IDE: Eclipse
And there are a couple of external dependent jar for manageTask.Java
Firstly your class name should be ManageTask.Java and not manageTask.Java.
To export jar, right click your project in eclipse, select Export int he popup menu and then choose jar int he wizard that opens. After that you should be able to find what you need.
Related
This is my first question on stack overflow.
Please have a look at this first, please!!
I am creating an executable jar file by clicking on the button surrounded with grey color. The problem is that the exxcution of the application always starts from the "PersonalAssistant.java".
I want my application to begin its execution from "App.java" which also contains a main() method.
So, basically the jar file which I want should begin its execution from App.java class which has a main method.
I don't know how to change the path or execution class for jar.
Please help me!!!! I'm stuck with this silly problem. But I want a solution for this.
I'm using Windows10 with Netbeans 8.2 IDE
You should be able to reconfigure your IDE and rebuild the executable jar specifying which class you want to use as the executable.
in your IDE add java -cp myjar.jar App
to your compile command
this might also help
Look at the picture above. Right-click on your project and select Properties. Select Run. Look for the Application Class field. In my example, I have javafxapplication211.Main. This structure is projectName.MainClass. You should just need to change the MainClass part to the class you want to start your project. For example, if Main.java was starting my app and I wanted to change it to App.java. I would change javafxapplication211.Main to javafxapplication211.App.
If you hit Browse, it will give you a list of available classes that can start the application.
I know how to add .java/class files to a certain project, or import them into a package. So, when you're using eclipse you can import java.awt.; and java.util.; and the but those are all packages inside the JRE. So my real question is: is there any way to import a package containing the files i want into the JRE so that, if i create a new project, I can simply import them whenever I need them? Thanks!
Yes. Generally, you have more then one choice. You can link the project(s) in eclipse, and then have project B with a reference to project A. Or, you can create a build artifact like a jar file and add it to the project B build/run path. Simply add a jar file to your project, right click and select Add to Build Path. Another alternative is to use a build tool that manages dependencies like gradle, sbt, maven, or apache ivy. Note that there are a wide variety of third-party opensource libraries you can add as dependencies using these (and other) tools.
You seem to be asking how to create a shared library, which in Java is a .jar file. The steps to do this in Eclipse are:
In the Package Explorer, you can optionally pre-select one or more Java elements to export. (These will be automatically selected in the Opens the JAR export wizard JAR Package Specification wizard page, described in Step 4.)
Either from the context menu or from the menu bar's File menu, select Export.
Expand the Java node and select JAR file. Click Next.
In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.
Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source files and resources. Note: Selected resources are exported in both cases.
In the Select the export destination field, either type or click Browse to select a location for the JAR file.
Select or clear the Compress the contents of the JAR file checkbox.
Select or clear the Overwrite existing files without warning checkbox. If you clear this checkbox, then you will be prompted to confirm the replacement of each file that will be overwritten.
Note: The overwrite option is applied when writing the JAR file, the JAR description, and the manifest file.
You have two options:
Click Finish to create the JAR file immediately.
Click Next to use the JAR Packaging Options page to set advanced options, create a JAR description, or change the default manifest.
Credit goes to the docs.
I'm trying to set up IntelliJ IDEA -- tried 12 and 13 -- Mac to use a Java class included a jar file for my Java application.
I've set the jar as a module dependency by the following procedure
Start from the "project window";
Select my main Java module;
Use menu File | Project Structure;
In Project Settings, select Modules, and select my Java application as interested module in the middle window;
On the window to the right, select "Dependencies" tab, and press "+" and select "Jars or directories" and navigate to the jar file, add select it so the custom jar file is added as a new entry in the window, check the Export checkbox and set Scope pulldown set as "Compile";
Press OK.
However, after setting this, in a Java class file in my Java application, if I use a class defined in the custom jar file, it still prompts me "Cannot resolve symbol 'SomeClass'".
Any idea what I'm doing wrong and how to fix this?
Edit:
my settings:
BTW, the Libraries and Global libraries are both empty. I tried to set the two jars there (separately) and add them as dependencies for the Java app, and had no luck, so I deleted them from Libraries and Global libraries. The above setting is using add module dependency as files directly (without first registering them as libraries), which still does not work.
Putting everything in the default unnamed package solved the issue.
I am new to JAVA. I am using Eclipse 3.7 with WindowBuilder Pro installed. I have made a JFrame SearchFrame.java using the GUI in the package SearchPackage.
But when I try to run this file it gives me the error:
Error: Could not find or load main class SearchPackage.SearchFrame
I looked into my output folder DatabaseSearch/bin and there is no .class file in it. Please suggest me what should I do to rectify this. Thanks in advance.
This worked for me
Try to:
Right click on the Project in PackageExplorer -> Properties -> Java Build Path
Select Order and Export tab, and move the source package that contains the main class to the top, by selecting the correct package and pressing the Up button.
Click right at project at Package Explorer the compile and run/
Automatic builds may be disabled preventing the class file from being generated. Right click on
DatabaseSearch > Build Project
to use the manual build feature
Please clear all the build errors if any in your project. May be the project has some missing jars as a result its not able to form .class file out of your java.
I am taking a course on Coursera and as part of a quiz I am supposed to download their xyz.class and run it. I want to do it in eclipse as all of jar files are added in eclipse and I dont want to modify the class path of system as it is very untidy.
But I dont know how to run a external .class file through?Can anyone help me with that?
Why do you want to run it in Eclipse ?
java classname
souhld do the trick. You can't use Eclipse to run an external class file with a main method without creatin a java project with this class in its class path.
Right-click your Eclipse project, Build Path, Configure Build Path, Libraries, Add (External?) Class Folder.
Just run
java xyz
eclipse might not required.
If you want to really work out through the eclipse then refer How do I include .class files in my project in Eclipse? (Java) answer.
There is another way of approach without using eclipse.
Approach is by creating a executable jar file and by including all required libraries & xyz.class.
Right click on the class file from the Package Explorer -> Run.
goto file >> new project >> Import>> add executable jar files >> select your path where you have stored your .class files>> check include in work place
apply>> ok >>>>>>>>>>>>>>>>>>>>Done