How to write Java code on Windows and compile and run on Linux

I am a new Java developer and would like to know if it is possible to write Java code on Windows using Eclipse, and the code really compiles and runs on Linux. I need to write a java program for Linux (Ubuntu), but I'm used to Windows for development.

I am thinking of using Samba for file sharing, so I can use Windows to access the source code, which is located in Ubuntu. But when I compile the code, it actually uses the Windows JVM, not the Ubuntu JVM, will it matter? Also, when I need to enable external JAR libraries that are in Ubuntu, the path actually looks like E: \ home \ java \ project \ abc.jar, where E: drive is a mapped network drive from Samba. so when I ran the program on Ubuntu there would no longer be D: drive.

So, I'm a little confused and wonder if this is possible at all. any help would be really appreciated

+3
source share
7 answers

Eclipse IDE . Windows Linux. .

+7

Java , , . , Windows Linux .

Linux, Windows. , , CLASSPATH.

, Windows CLASSPATH :

CLASSPATH=d:\jars\abc.jar;d:\jars\def.jar

Unix/Linux :

CLASSPATH=/home/user/lib/abc.jar:/home/user/lib/def.jar

( ).

,

java MyApp.jar

. CLASSPATH Java, script, . CLASSPATH , .

java -cp /home/user/lib/abc.jar:/home/user/lib/def.jar
+8

java JVM. java -, . - Java , JVM. java.

+2

Eclipse 3.5, , " → Runnable jar", FatJar, , .

, ant, . "java -jar foo/bar.jar".

, .

+2

, , JAR, .

JAR manifest, , .. , . D:\something.

Ant JAR, jar - , manifest .

:

<manifest>
    <attribute name="Specification-Title" value="Blablabla description"/>
    <attribute name="Class-Path" value="${classpath}"/>
</manifest>

"classpath" fileset, .

<path id="classpath">
    <fileset dir="${project.libdir}" includes="*.jar" />
</path>
+1

, samba ( .)

. , . (: SVN .)

Windows, eclipse.

, Linux. .

, , , , , , Ubuntu .

, , Windows, , , , FatJar plugin linux.

+1
source

Too many problems. why not use eclipse on ubuntu?

-3
source

Source: https://habr.com/ru/post/1715304/


All Articles