I have the following Java program in Intellij and I cant seem to figure out how to run the program from my mac terminal (or export everything to run it on a different computer). Currently the only way I can run the program is if I press RUN in the IDE. I assume I need a .jar file but where do I go to compile that? Any help would be greatly appreciated.
Open your project settings in the upper right corner (or ctrl+alt+shift+s) and go to "Artifacts". Then add Jar -> From modules with dependencies
Choose your Module and your Main-class and Submit and apply the project settings
After that you can go to Build -> Build Artifacts -> Build
IntelliJ creates the jar inside the "out" folder in your project folder.
(This is for simple Projects. If your project is a bit more complex, you might need more settings.)
#MadProgrammer: Before packaging a Java module into a JAR file, you need to configure an artifact of the type JAR. This artifact can define the output of one or more modules
Once I added the artifact and then build the artifact I am able to run the program via terminal
Related
I created a gradle project in Intellij idea. After building and running everything worked as expected. But I don't want to run an IDE everytime I need to use my program. Can anyone recommend a step-by- step guide?
You can quickly do it in IntelliJ following theses steps :
Go to File > Project Structure
Select Artifacts tab and click on the "+" icon
Choose to generate a JAR from modules with dependencies
Choose your module and its main class and save changes
Now go to Build > build artifacts > build*
It's done, your executable .jar file should be located in out/artifacts/module_name/module.jar
*Choose rebuild if it has already been built.
I have some problems while creating a jar of my intelliJ project. First of all I just do the usual procedure:
Go to project structure
Select artifacts
Create a new one with modules and dependecies
Go to build artifact, build it
Execute it at console with java -jar "ddddd.jar"
So when I execute the project (not the jar) all runs ok, libreries and all works, but not in the JAR.
Terminal of IntelliJ:
My libraries are located in the project like: project>lib>"some jars here">otherjars>"here some jars and respective dll
This is because the "other jars" need the dll to work. I already tried to run them without the .dll but doesn't work without it.
Also I have them in the project on Modules>Dependencies I have the folder selected as a library.
Any help would be appreciated.
Edit 1:
Here I add some pictures about how I have my libraries structured.
For a project I completed a game in Java on Eclipse using LibGDX. I now need to turn in the source code to my professor. When I export the project and try opening it on a new computer, about a dozen libraries are missing.
I would like to export my entire project so that when the project is opened in eclipse, it will still compile. Is there any way to do this? I know that runnable jars come with the .jar files of the dependencies and no source code, but I need both.
Thanks in advance
Libgdx required number of dependent jars so it's hard to manually add all jars into project.
Make your project gradle based so that When you import your project through gradle into another System then gradle do most of your task* for you.
*gradle try to find dependent jars in file system if already exist then link with your project if not then it download from given repository and link them in your project. Make sure your system is connected with internet when you build your project.
I highly encourage to use Android Studio or IntelliJIDEA.
On window, by default all jars are stored inside
C:\Users\User_name\.gradle\caches\modules-2\files-2.1
In Mac OSX
/Users/User_name/.gradle/caches/modules-2/files-2.1
When you want to deploy or packaging for the desktop run this command on your IDE terminal.
gradlew desktop:dist
You can use maven or gradle to build your project, take a look of one of the tool and it's won't take you too much time. these tool could help you define your own way for build
A much easier way you could use "fat jar". this is an old tool for build a jar with all lib you need and could be run in any place.
It's been tedious. This is the API I am trying to use. Its resources were set up in a pom.xml which I built using Maven. On built up, it gave me the project socrata-publisher that has
src/main/java the source folder with packages com.socrata.api com.socrata.data, com.socrata.util where each contains only .java
files
JRE System Library and Maven Dependency hierarchies where each contains a number of jar files
Problem is com.socrata.api and the 2 other contains classes which I want to deploy in a project outside socrata-publisher. I tried using import com.socrata.api but it didn't work. Moreover, since its a Java project and not android it doesn't have the is Library option in preferences which could rather give me the solution. Both socrata-publisher and tutorial (where i want to use the resources and which is the android application) lie in the same directory eclipseApps in My Documents.
Here's a little visual queue. Help will be greatly appreciated.
You will need to first of all get the output of the socrata project and all its dependencies.
In command line, going to the project folder of the socrata project, where the pom.xml file is, run MVN INSTALL. You shall see a jar file called socrata-api.jar in $HOME/.m2/repository. If you are using windows and installed MAVEN by default, $HOME should be your user profile folder. Once you see the jar file, add it to your tutorial build path.
I think what you actually want to do is just set up the "socrata-publisher" as a project dependency for your "tutorial" project. That will allow you to reference the built Socrata libraries from the code in your project.
Right click on the project and select "Properties". From within that dialog select "Java Build Path" on the left, then the "Projects" section, and click the "Add" button to add the "socrata-publisher" project.
I think that'll work better than creating a separate jar file that you then include, and then you can also keep the socrata-publisher code up to date using Git.
I have a huge project (Application) with another project inside it (Core). Application has a big set of libraries inside as does Core. I'm using Eclipse and so I'm using the Export Runnable Jar option to create Application.jar but when I run it part of the code uses the Core which has a dependency on an image library within that. When I look inside the runnable jar file all the libraries for the Application project are there but when I look inside the Core project jar file the libraries aren't there. To give you an idea of what I mean the structure I'm expecting looks like this:
Application
- Core.jar
+ ImageLibrary.jar
+ OtherLibraries.jar
:
+ OtherLibraries.jar
:
I'm using Maven to build the projects individually. But I'm not really an expert with Maven as I've only being using it for a short time.
Is it possible to build Application so that Core also has its libraries with it?
Thanks in advance,
Alexei Blue.
In your Maven build for Application, is Core not specified as a dependency? If so, it should be included with all its dependencies. You should probably check whether the dependencies themselves have the correct scope in Maven to be included.
Okay so I figured this one out in the end. When I was using Maven to build the project it was doing so and then not updating the build path in eclipse. So I in the core directory I ran:
# mvn clean install
# mvn eclipse:eclipse
As the image library was an addition to the Core dependencies I had to ensure that the build path for eclipse was set otherwise eclipse won't pick up the changes. The eclipse:eclipse command did this for me but I think it only works in projects that are one module, however it reads any dependencies from your pom file and ensures your project can see and access them.
And then in the App directory I re built the project:
# mvn clean install
Then from within eclipse I exported the App project as a Runnable Jar which worked fine.
Hope this helps anyone having the same problem.
Cheers,
Alexei Blue.