Deployment

OK. I am fairly new to the Java world (I have spent most of my time with .NET). I have a project that is running in a Windows environment under the IntelliJ IDE and everything seems to work the way I want. Now I would like to deploy to a Linux Ubuntu server and run the code there. To make sure that it runs what all do I need to copy? I am assuming that I need the compile class that contains 'main' as well as all of the classes that makeup my packages. This brings up my first question cann all of the class files that are part of the packages in the project be somehow combined so I just need to deploy one class file? If not what is the directory structure expected? Or do I just need a CLASSPATH environment variable that includes the classes of my package? Now what about the various jar files that make up the external libraries? What if I want to make my own JAR file? Thanks for help on these rudimentary questions.

0
37 comments
Avatar
Permanently deleted user

Hi Kevin,

You should package your files at one of standard java formats depending on your application type - jar, war or ear. The ide can help you here via artifacts subsystem.

Then you can simply deliver that archive to your linux box and launch it there.

Denis

0

Thank you I am trying to reorganize and am in a little trouble. I don't understand the idea of a package. I have added several files in the same directory as my App.main so my project layout looks like:

src
main
java
RiakImport

The folder RiakImport has a file called App.java that was created when I started the IntelliJ project (new project). This file contains my main. I have added a number of .java files to this same level but right now even though they are deining objects they are not recognized. However, once this is over come I would like to create a package with this files that I have added but I am not sure how to do this so the files and their contents are recognized. Ideas?

As far as the original question. Where do I find the project properties? I can get to 'Project Settings' and under Atifacts there is an arrow that gives me two menu choices. Either 'Empty' or 'From mondules with dependencies'. I have not created a "module" so how does that play with Facets, Artifacts, and Packages?

0
Avatar
Permanently deleted user
  1. *.java files should be organized in packages. 'Package' here is a very similar thing to c# namespace. The only difference is that package name defines directory structure, i.e. if your java class belongs to package 'foo.bar', that means that there must be a directory named 'foo', directory 'bar' inside 'foo' and your *.java file inside 'bar'. http://en.wikipedia.org/wiki/Java_package;
  2. You must have at least one module at your project. You can check what modules are configured for the current project at 'project settings | modules'. If no modules are there, you can create one via pressing '+' button - http://www.jetbrains.com/idea/webhelp/module.html;
  3. When your module is created, it should be configured in a way that your *.java files are located under source root;
  4. Artifacts -> from modules with dependencies should be used when the project is configured properly;


I'd recommend you to check out any existing pre-configured open source java project in order to check how a project is organized.

Denis

0

I created an 'artifact' but I don't see that a .jar file was produced. Now what am I missing?

0
Avatar
Permanently deleted user

Did you try to build the artifact via main menu | build | build artifacts?

Denis

0

I didn't know I needed to do this. Anyway I found the .jar file in the 'out' folder and copied the .jar file to my Linux machine and ran it like:

java -jar RiakImport.jar

But I get the message:

no main manifest attribute, in RiakImport.jar

Now what am I missing?

0
Avatar
Permanently deleted user

You need to include instructions about your application's entry point (a class with main() method) into the jar in order to be able to execute it via 'java -jar'. It's defined under 'Main-Class' key at jar's manifest - http://stackoverflow.com/questions/2848642/how-to-setup-main-class-in-manifest-file-in-jar-produced-by-netbeans-project.

IJ reference - http://www.jetbrains.com/idea/webhelp/output-layout-tab.html#manifestFile

Denis

0

I have attached what the artifact looks like. I looks like the Main-Class is defined?



Attachment(s):
Artifact.jpg
0
Avatar
Permanently deleted user

It looks so (assuming that class name is App and it's located at package RiakImport).

You can also check the resulting *.jar as it's a simple *.zip file. It's assumed that it has META-INF/MANIFEST.MF entry which contains a line like 'Main-Class: RiakImport.App'

Denis

0

I renamed the .jar file to .zip and looked to find the file and I only see:

Manifest-Version: 1.0

Export-Package: com.basho.riak.protobuf;uses:="com.google.protobuf";ve

rsion="1.2.1"

Built-By: roach

Tool: Bnd-1.50.0

Bundle-Name: Riak Protocol Buffers

Created-By: Apache Maven Bundle Plugin

Build-Jdk: 1.7.0_10

Bundle-Version: 1.2.1

Bnd-LastModified: 1356115859097

Bundle-ManifestVersion: 2

Bundle-Description: Protocol buffers used to communicate with Riak

Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt

Import-Package: com.google.protobuf

Bundle-SymbolicName: com.basho.riak.protobuf.riak-pb

0
Avatar
Permanently deleted user

'Created-By: Apache Maven Bundle Plugin' means that that is not a jar created by IJ.

Which jar did you check? Your artifacts is configured to produce output to C:\Temp\RiakImport\out\artifact\RiakImport_jar

Denis

0

This is the Jar that I checked. It is the only RiakImport.jar that is available.

I have attached a "history" of screen-shots of what I see.

Message was edited by: Kevin Burton



Attachment(s):
Artifact4.jpg
Artifact3.jpg
Artifact2.jpg
Artifact1.jpg
0
Avatar
Permanently deleted user

You can sumbit a sample project, I'll take a look.

Denis

0

Here is the whole folder zipped up. It is rather large.



Attachment(s):
RiakImport.zip
0
Avatar
Permanently deleted user

Looks like a bug at our new compiler. Please uncheck 'project settings | compiler | use external build' as a workaround.

Denis

0
Avatar
Permanently deleted user

The artifact editor shows wrong manifest file here, we already have an issue about that (http://youtrack.jetbrains.com/issue/IDEA-99596). main/java
directory in Maven project is supposed to contain java classes so MANIFEST.MF file from this directory won't be copied to the output by Maven and IDEA
follows this behaviour. To fix the problem you can move META-INF directory to main/resources.

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

I don't have a main/resources folder.

Message was edited by: Kevin Burton



Attachment(s):
RiakImport.jar
0
Avatar
Permanently deleted user

Then you need to create it (http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR).

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

 

kevin@devUbuntu01:~/RiakImport$ java -jar RiakImport.jar Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
 

 at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:240)
 

 at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:193)
 

 at java.util.jar.JarVerifier.processEntry(JarVerifier.java:262)

 

 at java.util.jar.JarVerifier.update(JarVerifier.java:216)

 

 at java.util.jar.JarFile.initializeVerifier(JarFile.java:345)

 

 at java.util.jar.JarFile.getInputStream(JarFile.java:412)

 

 at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:752)

 

 at sun.misc.Resource.cachedInputStream(Resource.java:77)

 

 at sun.misc.Resource.getByteBuffer(Resource.java:160)

 

 at java.net.URLClassLoader.defineClass(URLClassLoader.java:436)

 

 at java.net.URLClassLoader.access$100(URLClassLoader.java:71)

 

 at java.net.URLClassLoader$1.run(URLClassLoader.java:361)

 

 at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

 

 at java.security.AccessController.doPrivileged(Native Method)

 

 at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

 

 at java.lang.ClassLoader.loadClass(ClassLoader.java:423)

 

 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

 

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

 

 at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

 

kevin@devUbuntu01:~/RiakImport$

 

 

On a side not you really need to fix the web page. I cannot post to the forum at all. I continually get an error that it is an empty page, 'there is an error, please check below', or a prompt to leave the page after the post message.

Message was edited by: Kevin Burton



Attachment(s):
Artifact5.jpg
RiakImport.jar
0
Avatar
Permanently deleted user

Your artifact is configured to repack content of all library jars into the target jar but it seems that some library jar was signed so it won't load
when jar is modified. To avoid this error you can change the artifact configuration to pack only your classes to the target jar, copy all library jars
to the same output directory and link them to the target jar using Class-Path attribute in manifest.mf file. To do this easily you can create an
artifact using 'From modules with dependencies' item and choose 'copy to the output directory and link via manifest' option.


--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

That was the only option I had to create a .jar "From modules with dependencies". I am unclear what needs to change.

I have attached my project.

If I move one of the .jar files then I get a whole lot of undefined symbols.


If I create a new artifact with the option you suggested I get a lot of .jar files in the output artifact folder. If I copy all of these files to my Linux machine and run 'java -jar RiakImport.jar' I get a new exception:

kevin@devUbuntu01:~/RiakImport$ java -jar RiakImport.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/basho/riak/client/raw/config/Configuration
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: com.basho.riak.client.raw.config.Configuration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
kevin@devUbuntu01:~/RiakImport$


Message was edited by: Kevin Burton



Attachment(s):
RiakImport.zip
0
Avatar
Permanently deleted user

'Create Jar from Modules' should have two radio buttons under 'Jar files from libraries' group: 'extract to the target jar' which is selected by
default and 'copy to the output directory and link via manifest' which you need to select instead.

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Like I indicated earlier I created a new artifact (the project was attached) with this second option. But as I indicated I am not out of the woods yet as I still get a Java exception (again reproduced in an previous post).

0
Avatar
Permanently deleted user

It seems that MANIFEST.MF file was generated in wrong location (src/main/java) and the MANIFEST.MF file which is really used (located at
src/main/resources) doesn't have all required jars in Class-Path attribute. In order to fix the problem you need to move the MANIFEST.MF file with
proper Class-Path attribute to the right location (src/main/resources/META-INF).

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

I moved the manifest already as a work-around to an issue with IntelliJ that is known and being worked on (my understanding). It is in the right place right? Now what is the right Class-Path attribute? And how is it specified? You have the whole project I just want it to work the same as it does when running from the IDE.

I have attached a screen shot of where I currently have the resources folder.



Attachment(s):
Artifact5.jpg
0
Avatar
Permanently deleted user

Kevin,

Sorry but this forum is not a right place for studying java. I'd suggest you to check jar file specification, try to build the *.jar manually and ensure that it's working. As soon as you have a clear understanding on what is really going on under the hood, you can setup tooling (ide) for automating the task. We would be glad to assist when you know exactly what do you want to achieve and just can't figure out how to do that at the ide.

Denis

0

I am not studying Java. I am trying to get IntelliJ to generate a .jar fle that works and so far have been unable.

If you are unclear what i am trying to achieve I simply want to run the program that I have the same way that it runs under the IDE.

0

If I create the artifact as suggested to 'copy to the output directory and link via manifest'  I don't get an option to select a CLASSPATH. The CLASSPATH on the target machine is set to '.'

0
Avatar
Permanently deleted user

After moving the manifest to the right place under main/resources (by the way it isn't workaround for IntelliJ's issue, this is how Maven works, it
doesn't copy manifest.mf files from main/java folder) you recreated the artifact with 'copy to the output directory and link via manifest'. At that
time IDEA generated the new manifest.mf file with proper Class-Path attribute in the selected directory. I think you selected main/java folder (may be
it was suggested by default) so IDEA generated the right manifest.mf file in the wrong location. So to fix the problem you can either move the new
generated manifest.mf to main/resources) or recreate the artifact again and choose main/resources folder in 'Create Jar from Modules' dialog.

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

So the correct procedure when using IntelliJ with Maven is to
1) Build the project.
2) Edit the manifest file to include all .jar files that Maven includes
3) Move the manifest file to the main/resources folder.
4) Create an artifact with the 'copy to the output directory and link via manifest' option selected and pointing to the moved manifest folder.
5) Build the artifact

Right?

0

Please sign in to leave a comment.